Lab Description:
In this lab we will learn how to classified programs into classes, and create these classes with the appropriate fields and methods. We will ask the user to in put an input and output the time and cost.
Code:
public class NumberStats { private double first; private double last ; private double minimum; private double maximum; private double average; private double total; private int count; private double sum; int time = 0; double cost = 0; public NumberStats(){ this.count = 0; this.sum = 0; } public void setNewNumber(double newNumber){ count++; sum += newNumber; average = sum/count; time = (int ) (newNumber * average); cost = (newNumber *2); if(count == 1){ maximum = newNumber; first = newNumber; } if(newNumber 0){ last = newNumber; } if(newNumber > maximum){ maximum = newNumber; } total = newNumber + sum; } public double getFirst(){ return first; } public double getLast(){ return last; } public double getMinimum(){ return minimum; } public double getMaximum(){ return maximum; }
public class NumberStats { private double first; private double last ; private double minimum; private double maximum; private double average; private double total; private int count; private double sum; int time = 0; double cost = 0; public NumberStats(){ this.count = 0; this.sum = 0; } public void setNewNumber(double newNumber){ count++; sum += newNumber; average = sum/count; time = (int ) (newNumber * average); cost = (newNumber *2); if(count == 1){ maximum = newNumber; first = newNumber; } if(newNumber 0){ last = newNumber; } if(newNumber > maximum){ maximum = newNumber; } total = newNumber + sum; } public double getFirst(){ return first; } public double getLast(){ return last; } public double getMinimum(){ return minimum; } public double getMaximum(){ return maximum; } public double getAverage(){ return average; } public int getCount(){ return count; } public double getTotal() { return total; } public double getCost() { return cost; } public double getTime() { return time; } }
Screenshot: