All I need to know is if I am on the right track in terms of min and max, not neccessarily how to finish the program.
Please, reply yes or no, and if no, why.
And for the tester// here is what I have class AnnualFuelUse { // instance variables - replace the example below with your own private int day, sMiles, eMiles, dist; private double gUsed, mpg, ppg, cost; public AnnualFuelUse(int dy,int sM,int eM,double gU, double pPg) { // initialise instance variables day = dy; sMiles = sM; eMiles = eM; gUsed = gU; dist = 0; ppg = pPg ; mpg = 0.0; cost = 0.0; } public void calcDistance() { dist = eMiles - sMiles; } public int getDistance() { // put your code here return dist; } public void calcMPG() { // put your code here mpg = ((dist)/(gUsed)); } public double getMPG() { // put your code here return mpg; } public void calcCosts() { cost = (mpg * ppg); } public double getCost() { return cost; } }
I made some changes to tester again please review!?public class AnnualFuelUseTester { public static void main (String[] Args) { AnnualFuelUse[] aFUT = { new AnnualFuelUse(1, 45023, 45231, 10.00, 2.95), new AnnualFuelUse(4, 45231, 45480, 11.70, 2.99), new AnnualFuelUse(8, 45480, 45659, 9.30, 2.99) }; double [] mpg = new double[3]; double [] cost = new double[3]; double [] distance = new double[3]; for(int i = 0; i < distance.length; i++) { aFUT[i].calcDistance(); distance[i] = aFUT[i].getDistance(); } for(int i = 0; i < mpg.length; i++) { aFUT[i].calcMPG(); mpg[i] = aFUT[i].getMPG(); } for( int i = 0; i < cost.length; i++) { aFUT[i].calcCosts(); cost[i] = aFUT[i].getCost(); } double max = Double.MIN_VALUE; double min = Double.MAX_VALUE; for(int i = 0; i < 3; i++) { if( distance[i]> max) max = distance[i]; } for(int i = 0; i < 3; i++) { if( distance[i]< min) min = distance[i]; } double max1 = Double.MIN_VALUE; double min1 = Double.MAX_VALUE; for(int i = 0; i < 3; i++) { if( mpg[i]> max1) max1 = mpg[i]; } for(int i = 0; i < 3; i++) { if( mpg[i] < min1) min1 = mpg[i] ; } double max2 = Double.MIN_VALUE; double min2 = Double.MAX_VALUE; for(int i = 0; i < 3; i++) { if( cost[i]> max2) max2 = cost[i]; } for(int i = 0; i < 3; i++) { if( cost[i] < min2) min2 = cost[i] ; } } }


LinkBack URL
About LinkBacks
Reply With Quote

if not then tell whats happening that shouldnt be happening..its not bad to have stuff not go the way you want right away because it teaches you how to debug and gives you experience fixing problems...which is what programming is