Lab #3

Objective:
For this lab we were suppose to create a program named NumberStats, which provides methods to compute several statistics. This method had to compute, the 1st number, the last number, count the numbers that was entered, the min, max, total sum, and the average of the numbers that was entered by the user. But this program had to be done in two separate classes, one is called “NumberStats” and the other one is called TrainStats.

Code:
This is the NumberStat Code and then follows the TrainStats Code

public class NumberStats 
{
    private int num;
	private int fnum;
	private int lnum;
	private int count;
	private double average;
	private int max;
	private int min;
	private int totalnum;
	private int nummmount;
	public int getnumber() 
	{ 
		return num;
	}
	public int getfirstnumber() 
	{
		return fnum;
	} 
	public int getlastnumber() 
	{
		return lnum;
	}
	public int getcount() 
	{
		return count++;
	}
	public double getaverage() 
	{
		return average;
	}
	public int getmaximum() 
	{
		return max;
	}
	public int getminimum() 
	{
		return min;
	}
	public int gettotalnumber() 
	{
		return totalnum;
	}
	public int getnumberamount() 
	{
		return nummmount;
	}
}
import java.util.Scanner;
public class TrainStats 
{
	public static void main(String[] args) 
	{
		int number = 0;
		int numberamount = 0;
		int totalnumber = 0;
	    int firstnumber = number;
	    int lastnumber = number %10;
	    int count = 1;
	    double  average;
	    int max = 0;
	    int min = 1;
		Scanner input = new Scanner( System.in);
		System.out.println("Enter a Series of Numbers: ");
		System.out.println("Enter 0 when done: ");
		do 
		{
			number=input.nextInt();
			numberamount ++;
			totalnumber = totalnumber + number;
			if (number > max)
			{
				max=number;
				count=0;
			}
			if(number==max)
				count++;
			else if (number < min)  			{ 				min =number; 				count=1; 			} 			if(number==min) 			{ 	 				count ++; 			} 			if (count ==1) 			{ 				firstnumber = number; 			} 	 			else if (count >0)
			{
				lastnumber = number;
			}
		}
		while (number !=0);
		average=(double)totalnumber/(numberamount-1);
		System.out.printf("The average is %.2f\n", average);
		System.out.println("Total Numbers Entered: " + numberamount);
		System.out.println("The Sum is " + totalnumber);
		System.out.println("The Maximum Number is\t: " + max);
		System.out.println("The Minimum number is: " + min);
		System.out.printf("First Number Entered is " + firstnumber);
		System.out.printf("\nLast Number Entered is  " + lastnumber); 

		NumberStats mystats1 = new NumberStats();
		NumberStats mystats2 = new NumberStats();
		NumberStats mystats3 = new NumberStats();
		NumberStats mystats4 = new NumberStats();
		NumberStats mystats5 = new NumberStats();
		NumberStats mystats6 = new NumberStats();
		NumberStats mystats7 = new NumberStats();
		NumberStats mystats8 = new NumberStats();

		System.out.printf("%s\n" , mystats1.getmaximum());
		System.out.printf("%s\n" , mystats2.getminimum());
		System.out.printf("%s\n" , mystats3.getaverage());
		System.out.printf("%s\n" , mystats4.getlastnumber());
		System.out.printf("%s\n" , mystats5.getfirstnumber());
		System.out.printf("%s\n" , mystats6.getnumber());
		System.out.printf("%s\n" , mystats7.getnumberamount());
		System.out.printf("%s\n" , mystats8.gettotalnumber());
	}
}

ScreenShots: