Lab 3

Lab Description:

The main point of this lab was to learn how to break down the program into classes. We were implementing what we had learned in lab 2 into lab 3 were we combined two codes were one would call on the other. We were told to use overloading if possible but when i tried to use overloading it was complex and i could not get the program to work. The two program asked to make were NumberStats and TrainStats. NumberStats did all the calculation of the program while TrainStats called the data and displayed it to the user.


public class NumberStats {

	private double firstNumber;
    private double lastNumber;
    private int count;
    private double max;
    private double min = 1000;
    private double average;
    private double sum;
    private double InputNumber;

    public void setNumber( double InputNumber){

        sum += InputNumber;
        if (InputNumber >= max){
            max = InputNumber;

        if (InputNumber 0.0 ){   
            lastNumber = InputNumber;

    public double getFirstNumber(){
        return firstNumber;
    public double getLastNumber(){
        return lastNumber;
    public double getCount(){
        return count;
    public double getMax(){
        return max;
    public double getMin(){
        return min;
    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: ", getMax() );
        System.out.printf("Minimum %s\n: ", getMin() );
        System.out.printf("Average %s\n: ", getSum()/getCount() );
        System.out.printf("Count %s\n: ", getCount() );
        System.out.printf("Totel Sum %s\n: ", getSum() );


import java.util.Scanner;

public class TrainStats {

    public static void main(String[] argss)
        Scanner input = new Scanner( );

        double InputNumber = 1;

        NumberStats myStatsDouble = new NumberStats();
        while (InputNumber != 0)

            System.out.print("Enter any number,to exit enter 0: ");
            InputNumber = input.nextDouble();
            if( InputNumber ==0.0 ) break;


Screen Shot: