This code section is from the main method of my Annual Fuel Use class. The program projects my annual fuel usage based on at least three fill ups of my car. Here, I am calculating the max and min for distance (which is miles traveled), MPG, and price per gallon. I'd like a general review.
//initialization of array of objects
AnnualFuelUse[] fillUps = {new AnnualFuelUse (1, 1, 6500, 6800, 9.70, 3.11),
new AnnualFuelUse (2, 10, 6800, 7052, 8.10, 3.08),
new AnnualFuelUse (3, 20, 7052, 7349, 9.20, 3.15)};
//calculate Min and Max for distance, MPG, and price per gallon
double minDist = 0, maxDist = 0;
double minMPG = 0.0, maxMPG = 0.0, minPrice = 0.0, maxPrice = 0.0;
Double dMin = Double.MAX_VALUE;
Double dMax = Double.MIN_VALUE;
Double mpgMin = Double.MAX_VALUE;
Double mpgMax = Double.MIN_VALUE;
Double priceMin = Double.MAX_VALUE;
Double priceMax = Double.MIN_VALUE;
for (int i = 0; i < fillUps.length; i++) {
if (fillUps[i].getDist() < dMin){
dMin = fillUps[i].getDist();
minDist = dMin;
}
if (fillUps[i].getDist() > dMax) {
dMax = fillUps[i].getDist();
maxDist = dMax;
}
if (fillUps[i].getMilesPerGallon() < mpgMin) {
mpgMin = fillUps[i].getMilesPerGallon();
minMPG = mpgMin;
}
if (fillUps[i].getMilesPerGallon() > mpgMax) {
mpgMax = fillUps[i].getMilesPerGallon();
maxMPG = mpgMax;
}
if (fillUps[i].getPrice() < priceMin) {
priceMin = fillUps[i].getPrice();
minPrice = priceMin;
}
if (fillUps[i].getPrice() > priceMax) {
priceMax = fillUps[i].getPrice();
maxPrice = priceMax;
}
}
>
to<
. As per your StackOverflow question \$\endgroup\$