but also to help me understand exactly how this works as i havent been able to find any good insructional information on this particular topic.
public int calcDistance(int distance, int endMiles, int startMiles)
{
distance = endMiles - startMiles;
return distance;
}
the above will calculate the distance obviously. It has three parameters: distance, end miles, and start miles. Inside you have it calculate the distance automatically.
public double calcMPG(int mpg, int distance, int gallons)
{
mpg = distance/ gallons;
return mpg;
}
this could be explained almost exactly like the one above, but with different paramters
//main method
public static void main(String[] args)
{
int startMiles1 = 55;
int endMiles1 = 250;
int gallons1 = 15;
int distance1, mpg1;
distance1 = calcDistance(distance1,endMiles1,startMiles1);
mpg1 = calcMPG(mpg1 ,distance1);
System.out.println(" Gas Mileage Calculations");
System.out.println("Type of Car Start Miles End Miles Distance Gallons Miles/Gallons");
System.out.println("==========================================================================");
System.out.printf("Saturn %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f" + startMiles1 + endMiles1 + distance1 + gallons1 + mpg1);
}
}
This main method sets the start miles, end miles, and gallons with specific integers. Distance and mpg have no specific integers but will receive them once they are plugged in.
distance1 = calcDistance(distance1, endMiles1, startMile1);
This is basically saying this: calcDistance(distance1, 250, 55);
Now remember calcDistance figures out the distance1 for you due to the calculation inside the method. So distance1 will now equal 195.
mpg1 = calcMPG(mpg1, distance1);
This will be: calcMPG(mpg1, 195);
So plug that into the equation: mpg = 195/15 which is 13.
I'm not sure if that's what you were looking for, but hopefully it was. If you need it broken down more, state so.
*Edit*
Just noticed chunalt787 replied