lab3

Lab Description:

In lab #3 we are to repeat the same thing we did in lad #2 to call out firstnumber, lastnumber, average, maximum,minimum, count and sum numbers. But in this lab we have to write two program to run this instead of one hole program to run the hole thing. The first program runs and ask the user for the input of numbers in to it. Then the second part of the program compute the numbers with the coding in it. After that the second program will give out the output.

CODE

package lab3;

import java.util.Scanner;

public class TrainStatsDouble {

	public static void main(String[] argss)
	{
		Scanner input = new Scanner( System.in );

		double InputNumber = 1;

		NumberStatsDouble myStatsDouble = new NumberStatsDouble();
		while (InputNumber != 0)
		{
			//	display the menu
			// read the value entered by user
			System.out.print("Enter A Number,to exit enter 0: ");
			InputNumber = input.nextDouble();
			if( InputNumber ==0.0 ) break;
			myStatsDouble.setNumber(InputNumber);

		}
		myStatsDouble.displayMessage();
	}   
}
package lab3;

public class NumberStatsDouble {

	private double firstNumber; 
	private double lastNumber;
	private int count;
	private double maximum;
	private double minimum =920006372;
	private double average;
	private double sum;
	private double InputNumber;

	public void setNumber( double InputNumber){

		//	copy file here

		sum += InputNumber;
		if (InputNumber >= maximum){
			maximum = InputNumber;
		}

		if (InputNumber 0.0 ){	
			lastNumber = InputNumber;
		}

	}
	public double getFirstNumber(){
		return firstNumber;
	}
	public double getLastNumber(){
		return lastNumber;
	}
	public double getCount(){
		return count;
	}
	public double getMaximum(){
		return maximum;
	}
	public double getMinimum(){
		return minimum;
	}
	public double getAverage(){
		return average;
	}
	public double getSum(){
		return sum;
	}

	public void displayMessage()
	{
		System.out.printf("First Number %s!\n: ", getFirstNumber() );
		System.out.printf("Last Number %s!\n: ", getLastNumber() );
		System.out.printf("Maximum %s!\n: ", getMaximum() );
		System.out.printf("Minimum %s!\n: ", getMinimum() );
		System.out.printf("Average %s!\n: ", getSum()/getCount() );
		System.out.printf("Count %s!\n: ", getCount() );
		System.out.printf("Totel Sum %s!\n: ", getSum() );
	}
}
package lab3;

import java.util.Scanner;

public class TrainStats {

	public static void main(String[] argss)
	{
		Scanner input = new Scanner( System.in );

		int InputNumber = 0;

		NumberStats myStats = new NumberStats();
		while (InputNumber != 0)
		{
			//	display the menu
			// read the value entered by user
			System.out.print("Enter A Number,to exit enter 0: ");
			InputNumber = input.nextInt();
			if( InputNumber ==0 ) break;
			myStats.setNumber(InputNumber);

		}
		myStats.displayMessage();
	}
}
package lab3;

public class NumberStats {

	private int firstNumber; 
	private int lastNumber;
	private int count;
	private int maximum;
	private int minimum =920006372;
	private int average;
	private int sum;
	private int InputNumber;

	public void setNumber( int InputNumber){

		//	copy file here

		sum += InputNumber;
		if (InputNumber >= maximum){
			maximum = InputNumber;
		}

		if (InputNumber 0 ){	
			lastNumber = InputNumber;
		}

	}
	public int getFirstNumber(){
		return firstNumber;
	}
	public int getLastNumber(){
		return lastNumber;
	}
	public int getCount(){
		return count;
	}
	public int getMaximum(){
		return maximum;
	}
	public int getMinimum(){
		return minimum;
	}
	public int getAverage(){
		return average;
	}
	public int getSum(){
		return sum;
	}

	public void displayMessage()
	{
		System.out.printf("First Number %s!\n: ", getFirstNumber() );
		System.out.printf("Last Number %s!\n: ", getLastNumber() );
		System.out.printf("Maximum %s!\n: ", getMaximum() );
		System.out.printf("Minimum %s!\n: ", getMinimum() );
		System.out.printf("Average %s!\n: ", getSum()/getCount() );
		System.out.printf("Count %s!\n: ", getCount() );
		System.out.printf("Totel Sum %s!\n: ", getSum() );
	}
}

Screen shot: