i am trying to make a program that takes an object oriented approach to calculating the miles per gallon that your car gets. this is early in the process an i am aware that alot of stuff is missing. i am just trying to get it to work enough that i can figure it out. i can only go by examples of oop design because my resources are limited, so if something doesnt make sense, sorry. anyway, here is my code:
/**
* The purpose of this program is to demonstrate the use of a constructor
* that takes parameters. Notice that there is no problem with two constructors
* with the same name as long as their parameter lists are different. This is
* referred to as overloading a constructor,
*
* ©FLVS 2007
* @author B. Jordan
* @version 05/28/07
*/
public class CarV5
{
CarV5()
{
}
public int calcDistance(int distance, int endMiles, int startMiles)
{
distance = endMiles - startMiles;
return distance;
}
public double calcMPG(int mpg, int distance, int gallons)
{
mpg = distance/ gallons;
return mpg;
}
//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);
}
}