I am trying to right a program that calculates MPG of a car and then resets the odometer.
I set up a class for the odometer and then am trying to call in the different methods into main.
Here is the odometer class:
import java.util.Scanner;
public class Odometer
{
public int milesDriven;
public int milesPerGallon;
int first;
int last;
int gals;
public int calculateMPG()
{
return(last - first)/gals;
}
public void setOdometer()
{
milesDriven = 0;
}
public int calculateMiles()
{
return (first + last);
}
public void readMileage()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the starting number of miles on odometer");
System.out.println("Enter the ending number of miles on odometer");
System.out.println("Enter gallons of gas pumped");
first = keyboard.nextInt();
last = keyboard.nextInt();
gals = keyboard.nextInt();
}
}
The main method is:
public class OdometerReading
{
public static void main(String[] args)
{
Odometer miles = new Odometer();
miles.readMileage();
System.out.println("The Miles are " + miles);
System.out.println("Miles per gallon is "+ miles.calculateMiles());
System.out.println("Miles per gallon is "+ miles.calculateMPG());
miles = setOdometer();
System.out.println("Current Miles "+ miles);
}
}
The compile error is at the setOdometer method it is:
OdometerReading.java:17: cannot find symbol
symbol : method setOdometer()
location: class OdometerReading
miles = setOdometer();
^
1 error
Tool completed with exit code 1
The files are saved in the same folder. I cannot figure out what I am missing here or what other problems I may be facing. Any and all help would be greatly appreciated.
TJ
I set up a class for the odometer and then am trying to call in the different methods into main.
Here is the odometer class:
import java.util.Scanner;
public class Odometer
{
public int milesDriven;
public int milesPerGallon;
int first;
int last;
int gals;
public int calculateMPG()
{
return(last - first)/gals;
}
public void setOdometer()
{
milesDriven = 0;
}
public int calculateMiles()
{
return (first + last);
}
public void readMileage()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the starting number of miles on odometer");
System.out.println("Enter the ending number of miles on odometer");
System.out.println("Enter gallons of gas pumped");
first = keyboard.nextInt();
last = keyboard.nextInt();
gals = keyboard.nextInt();
}
}
The main method is:
public class OdometerReading
{
public static void main(String[] args)
{
Odometer miles = new Odometer();
miles.readMileage();
System.out.println("The Miles are " + miles);
System.out.println("Miles per gallon is "+ miles.calculateMiles());
System.out.println("Miles per gallon is "+ miles.calculateMPG());
miles = setOdometer();
System.out.println("Current Miles "+ miles);
}
}
The compile error is at the setOdometer method it is:
OdometerReading.java:17: cannot find symbol
symbol : method setOdometer()
location: class OdometerReading
miles = setOdometer();
^
1 error
Tool completed with exit code 1
The files are saved in the same folder. I cannot figure out what I am missing here or what other problems I may be facing. Any and all help would be greatly appreciated.
TJ