Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error

Status
Not open for further replies.

tberger1

MIS
Sep 12, 2006
16
US
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
 
That class hasn't a method called Odometer.

Maybe what you want to do is
Code:
miles.setOdometer();

Anyway, you should post questions like this in the Java forum, this one is for J2EE questions.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top