Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is awesome!...Things I have been trying to figure out for weeks, I got the answer in hours!..."

Geography

Where in the world do Tek-Tips members come from?
tberger1 (MIS)
10 Oct 06 11:52
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
Diancecht (Programmer)
10 Oct 06 13:51
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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close