Okay, I am having more difficulty with my Java class again. My professor assigned us a 2-D chart program... This is the output he wants:
This program displays the annual cost of gasoline for different mpg
and price per gallon of gas assuming 18,000 miles driven annually.
MPG 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25
-------------------------------------------------------------------
5 5,400 6,300 7,200 8,100 9,000 9,900 10,800 11,700
10 2,700 3,150 3,600 4,050 4,500 4,950 5,400 5,850
15 1,800 2,100 2,400 2,700 3,000 3,300 3,600 3,900
20 1,350 1,575 1,800 2,025 2,250 2,475 2,700 2,925
25 1,080 1,260 1,440 1,620 1,800 1,980 2,160 2,340
30 900 1,050 1,200 1,350 1,500 1,650 1,800 1,950
35 771 900 1,028 1,157 1,285 1,414 1,542 1,671
40 675 788 900 1,013 1,125 1,238 1,350 1,463
45 600 700 800 900 1,000 1,100 1,200 1,300
Use the principles of encapsulation and generalization design your program with efficient functions. The formula for annual cost is:
annualCost = (18000 / mpg) * pricePerGallon
Below is what I have so far...
public class HW04_jsn
{
public static void main(String [] args)
{
double fuelCost[][] = new double [9][8];
System.out.println("MPG\t\t1.50\t\t1.75\t\t2.00\t\t2.25\t\t2.50\t\t2.75\t\t3.00\t\t3.00");
System.out.println("------------------------------------------------------------------------------------------------------");
int mpg = 5;
for (int m = 0; m < 9; m++);
{
System.out.println(mpg + "\t");
for (int cost = 0; cost < 8; cost++)
{
System.out.print(annualCost.format(mpg[m][cost]));
System.out.print("\t");
}
mpg++;
System.out.println();
}
}
public static double annualCost
(double m, double cost)
{
double annualCost = (18000 / m) * cost;
return annualCost;
}
}
The errors I am getting are:
cannot find variable m
array required, but int found
cannot find variable annualCost
(All on line 23)
I just don't know what I am doing wrong... every time I make a change, something else is sending an error. Could anyone please explain to me (as simply as possible) how to program a chart?
I do not ask that you give me the answer to my assignment, just some help to clarify things for me. You all were very helpful with the last assignment that I had problems with and I do greatly appreciate the advice.