Average Fuel Mileage program
807601Mar 2 2008 — edited Mar 2 2008Good all,
I am trying to write a program class "FuelEfficiencyCaloculator". I think I have it mostly correct but it doesn't run properly. I understand the concept but am having trouble visualizing the overall product. I think I have the "methods" correct. Could someone please look it over and explain to me where I have gone off track? The program is supposed to input up to seven days of miles driven and seven days of fuel added, then, give an average miles per gallon at the end. Thanks to anyone that can help.
Here is my code:
Import java.util.Scanner;
Public class FuelEfficiencyCalculator
{
public static void main(String[]args)
{
int gas,fuel, miles, mileage;
double mpg;
}
public void accrueGasUsed (int i);
{
boolean done = false;
while (!done) // sentinel value to terminate loop
{
System.out.print (?Please enter gas used per day in gallons, Q to quit: ?);
input = in.next();
for (int i = 1; i < 8; i++)
If (input.equalsIgnoreCase(?Q?))
done = true;
else
{
fuel = fuel + input;
}
return fuel;
double gas = Double.parseDouble (fuel);
fuel.add (gas);
}
}
public accrueMilesDriven (int i);
{
boolean done = false;
while (!done) // sentinel value to terminate loop
{
System.out.print (?Please enter miles driven per day, Q to quit: ?);
String input = in.next();
for (int i = 1; i < 8; i++)
If (input.equalsIgnoreCase(?Q?))
done = true;
else
{
miles = miles + input;
}
return miles;
double mileage = Double.parseDouble (miles);
miles.add (mileage);
}
}
public getAverageEfficiency ();
{
mpg = mileage / gas;
}
return mpg;
System.out.println (?Average fuel used= ? + gas.getAverage ());
System.out.println (?Average miles driven = ? + mileage.getAverage());
System.out.println (?Average miles per gallon = ? + mileage());
}