0
/**
 * @(#)Car.java
 *
 *Chp.3 3.5
 * @author Alec Ziff
 * @version 1.00 2011/9/23
 */


public class Car {
{
    public Car(double fuelEffciency) //all values are in miles per gallon

    {
    	efficiency= fuelEfficiency;
    }

    public void addGas(double gas)
    {
    	double newFuel= fuel + gas;
    	fuel= newFuel;
    }
 		public double drive( double distance)
 		(
 			double fuelLevel = fuel - (distance/efficiency);
 			fuel= fuelLevel;
 			return fuel;
		)
 	
		public double getGasInTank()
		{
			return fuel;
		}
		private double fuel;
		private double efficiency;
}
}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by NormR1
0

Figured it out.But I have a new question on its tester class.

public class CarTester {
	public static void main (String[] args)
	{
		Car myMysteryMachine = new Car (1000); // Car gets 1000 miles per gallon
		myMysteryMachine.addGas(20); // 20 gallons of gas are added to the tank
		myMysteryMachine.drive(100); // Driving the car 100 miles
		System.out.println(myMysteryMachine.getGasInTank()); // Method prints the remaining fuel
		
	}
}

It says it cannot find the symbol on line 12. that would be the "Car myMysteryMachine = ...

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Please copy and paste the FULL text of the error message. You are leaving parts of it off.

Here is a sample:

TestSorts.java:138: cannot find symbol
symbol  : variable var
location: class TestSorts
         var = 2;
         ^
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.