Description
The Main objective of this lab is to learn how to break down a program into classes, and therefore create a classes with their respective fields and methods, using method overloading. For instance, in order to do this type of program first you’ll need to create a program called NumberStats to do all the menu for the calculations. Second, you need to create another program called TrainStats this program will have the function of computing all the data from Numberstats using methods and calling each class according to which fields they belong to.
Codes
NumberStats
// Lab 3 by Julio Tax public class NumberStats { public static void main(String[] args) { } private double DoubleMinimum; private double DoubleMaximum; private double DoubleFirstNum; private double DoubleLastNum; private int IntMinimum; private int IntMaximum; private int IntFirstNum; private int IntLastNum; private int Count; private double totals; private double averages; public void setMinimum(int number){ IntMinimum=number;} public void setMaximum(int number){ IntMaximum=number;} public void setFirstNum(int number){ IntFirstNum=number;} public void setLastNum(int number){ IntLastNum=number;} public void setMinimum(double number){ DoubleMinimum=number;} public void setMaximum(double number){ DoubleMaximum=number;} public void setFirstNum (double number){ DoubleFirstNum=number;} public void setLastNum(double number){ DoubleLastNum=number;} public void setCount(){ Count++;} public void settotals(double number){ totals=totals+number;} public void setaverages(){ averages=totals/Count; } public int getIntMinimum(){ return IntMinimum;} public int getIntMaximum(){ return IntMaximum;} public int getIntFirstNum(){ return IntFirstNum;} public int getIntLastNum(){ return IntLastNum;} public int getCount(){ return Count;} public double getDoubleMinimum(){ return DoubleMinimum;} public double getDoubleFirstNum(){ return DoubleFirstNum;} public double getDoubleLastNum(){ return DoubleLastNum;} public double getDoubleMaximum(){ return DoubleMaximum;} public double gettotals(){ return totals;} public double getaverages(){ return averages; } public void displayTrainStats(){ System.out.println("The following are the Caculations: "); System.out.printf("\nMinimum values is: \n",getIntMinimum()); System.out.printf("\nMaximum value is: \n", getIntMaximum()); System.out.printf("\nThe First Number is: \n",getIntFirstNum()); System.out.printf("\nThe Last Number is: \n",getIntLastNum()); System.out.printf("\nThe Total Sum of numbers is: %.2f\n", gettotals()); System.out.printf("\n The count of numbers enterd is: \n", getCount()); System.out.printf("\n The Average is: %.2f\n", getaverages());} public void displaycostsStats() { System.out.printf( "\nMinimum is %.2f\n", getDoubleMinimum()); System.out.printf( "\nMaximum is %.2f\n", getDoubleMaximum()); System.out.printf( "\nFirst number is %.2f\n", getDoubleFirstNum()); System.out.printf( "\nLast number is %.2f\n", getDoubleLastNum()); System.out.printf( "\nCount of number entered is %d\n", getCount()); System.out.printf( "\nTotal Sum is %.2f\n", gettotals()); System.out.printf( "\nAverage is %.2f\n", getaverages()); } }
TrainStats
// Lab3 By Tax Julio import java.util.Scanner; public class TrainStats { public static void main(String[] args) { int menuChosen; Scanner input=new Scanner(System.in); NumberStats mynumbers=new NumberStats(); System.out.println("1: One Way Trip Costs!!"); System.out.println("2: One Way Trip Time In Minutes"); System.out.println("OR! you can press any other number that you desire "); menuChosen=input.nextInt(); if(menuChosen==1) { System.out.println("You Have Selected One Way Trip Costs"); System.out.println("Now please enter your values OR 999 to quit: "); double costs=input.nextDouble(); if (costs!=999) { mynumbers.setFirstNum(costs); mynumbers.setLastNum(costs); mynumbers.setMinimum(costs); mynumbers.setMaximum(costs); } while (costs!=999){ mynumbers.settotals(costs); mynumbers.setCount(); if(mynumbers.getCount()>1){ if (costs>mynumbers.getDoubleMaximum()) mynumbers.setMinimum(costs); else if(costs < mynumbers.getDoubleMinimum()) mynumbers.setMinimum(costs);} System.out.print("Please enter double values or 999 to exit: "); costs=input.nextDouble(); if (costs !=999) mynumbers.setLastNum(costs);} if (mynumbers.getCount() !=999){ mynumbers.setaverages(); mynumbers.displaycostsStats(); } else System.out.println( "Try again, no numbers were read!!!!" ); } else if (menuChosen==2){ System.out.println("You have picked Trip Time: "); System.out.println("please enter integer values or 999 to exit"); int step=input.nextInt(); if(step!=999){ mynumbers.setFirstNum(step); mynumbers.setLastNum(step); mynumbers.setMinimum(step); mynumbers.setMaximum(step);} while(step!=999){ mynumbers.settotals(step); mynumbers.setCount(); if ((mynumbers.getCount())>1){ if(step>(mynumbers.getIntMaximum())) mynumbers.setMaximum(step); else if (step
Screenshots