LAB 1

Lab Report 1

Lab Description:

In this lab, the instructions were to create a program that can ask the user to input as many numbers as they wish, so it can compute several statistics. The program will decide on which two numbers are considered the highest and lowest numbers. Next, the program will calculate the total sum by taking the highest and lowest numbers, then calculate the average. Also,  the program should determine the amount of numbers the user has input. However, I have made errors to this program that the program doesn’t do exactly what it was supposed to do.  First, i created a menu option for the user; asking them if they would like to enter a number or exit the program. If the user press 1, they want to enter a number. If they press two, they want to exit the program. Next, after the user press 1, the program ask them to enter a number. In the program itself, there are variables that are assigned 0, meaning that there are no numbers entered that are greater or lower than 0. Once the user enter a number, the program will take that number and determine if that number meets the conditions of the if statement. Next, after the user has entered a number that number will be considered the current number, then that same number could be the highest or lowest number. Instead of displaying which number is the  highest and lowest number it would take the first number and add it to itself because the program considers that number to be the highest and lowest number. If the user runs the program again and enters a bigger number than the previous number, it will use that number and add it to itself. However, if the next number the user enters is lower than the last number, it will add the previous number to itself instead of the last number the user put in.

Code:

 

package Numbers;
import java.util.Scanner;
public class Numbers {

	public static void main(String args[]) {
		Scanner input = new Scanner(System.in);
		int counter = 0;
		int sum = 0;
		int average = 0;
		int firstnum = 0;
		int lastnum = 0;
		int countnum = 0;
		int highestNum = 0;
		int previousHighest = 0;
		int lowestNum = 0;
		int previousLowest = 0;
		int option = 0;
		int currentNum = 0;
		do{
			System.out.println("Menu: (1) Enter a number (2) Exit");
			option = input.nextInt();
			if (option == 1 ){
				System.out.println("Enter next number:");
				currentNum = input.nextInt();
				if (counter == 0){
					firstnum = currentNum;
					lastnum = currentNum;

				}
				counter++;
				firstnum = counter;
				lastnum = counter;
				if (currentNum>highestNum){
					System.out.println("This is the highest number");
					previousHighest = highestNum;
					highestNum = currentNum;

				}				

				if (currentNum < lowestNum);{
					System.out.println("This is the lowest number");
					previousLowest = lowestNum;
					lowestNum =currentNum;

					System.out.println("Results");
					sum = highestNum + lowestNum;
					System.out.println(sum);}}
			counter++;
		}while(option != 2);		
	}
}

Screenshots:

PRO

Leave a Reply

Your email address will not be published. Required fields are marked *