Lab 1

Description:

Well for this java lab, I had to declare certain variables so that the program can know which are needed to put in the numbers for it to work. I also had to use the scanner protocol due to the fact that for me to actually enter the numbers while the program is being executed, scanner will help to allow me the programming rights to enter any number I want. It can be either positive or negative numbers, as long a scanner is mention in the code, it will be allowed. The statements needed to be used in this lab are the if/else and do..while loop statements. The only trouble I had in this lab was to remember again how to use if/else statements.

/**
 * 
 * @AntonScott
 *
 */
import java.util.Scanner;
public class lab1 {
	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);

		int namecounting = 1;

		int numb1= 0;
		int numbs;
		int numfist = 0;
		int total = 0;
		int aver = 0;
		int decision;

		System.out.println("Please choose 1 to enter a number or 2 to exit: ");
		decision = input.nextInt();

		if (decision == 2)
			{
			System.exit(0);
			}

		System.out.println("Please enter the amount of numbers you will be entering: ");
		numbs = input.nextInt();

		System.out.println("Please enter your first number: ");
		int noa1 = input.nextInt();

		int min1 = noa1;
		int min2 = noa1;

		int max1 = noa1;
		int max2 = noa1;

	do	

		if (decision == 1)

		{		

			System.out.println("Please enter your number: ");
			numb1 = input.nextInt();

		// Minimum two numbers

		if (numb1 <= min1) 
		{
            min2 = min1;
            min1 = numb1;
        } 

		else if (numb1 < min2)  		{             min2 = numb1;         }  		 		else if (min1 == min2)    		{             min2 = numb1; 		} 	                 	   		// maximum two numbers 		 		if (numb1 >= max1) 
		{
            max2 = max1;
            max1 = numb1;
        } 

		else if (numb1 > max2) 
		{
            max2 = numb1;
        } 

		else if (max1 == max2)   
		{
            max2 = numb1;
		}

		// 1st Number
		if (namecounting == 1)
			{
			numfist = noa1;
			}

		// Total
			total += numb1;

		// Average
			aver = total / namecounting;

		namecounting ++;  

	}

	while (namecounting < numbs);

		// Total
		total = total + noa1;

		// Average
		aver = total / namecounting;

		System.out.printf("The first number is: %d\n", numfist);
		System.out.printf("The last number is: %d\n", numb1);
		System.out.printf("Count of number entered: %d\n", namecounting);
		System.out.println("The two smallest numbers are " + min1 + " and " + min2);
		System.out.println("The two highest numbers are " + max1 + " and " + max2);
		System.out.printf("The total sum of your numbers is: %d\n", total);
		System.out.printf("The average of your numbers is: %d", aver);

	}

}

Lab1

Lab1 part2

Leave a Reply

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