Roel
2009-06-03 13:30:15 UTC
Thanks a lot if you would help.
You are requested to construct a Car class containing the following attributes:
- a double variable containing the size of the engine (e.g. 1.8 litres),
- a String variable indicating the kind of fuel (diesel, regular, super),
- a counter mimicking the total number of kilometres driven by the car,
- a fuel indicator indicating the amount of litres in the fuel tank.
Cars can be created having values for each of these variables.
The services available on the Car class are:
- a constructor creating an object with sensible default values for the attributes,
- a constructor creating a car object with user defined values for the attributes,
- a toString() method printing the values of all the attributes of a car,
- an assignment method that performs an assignment of all the attributes of car1 to car2.
- a method to make a trip (adding the number of kilometres driven to the counter, and subtracting an amount of gas from the tank; the amount being linearly dependent upon the kilometres driven.).
- an equals()-method that checks whether two cars are 'the same'. Two cars are defined to be the same if all their attributes, except for the counter and the fuel indicator, are identical.
Create a class TestCars to test the system. This class will contain the main( ) method. In this main method several cars will be constructed using both forms of the constructor.
- try out the equals()-method on these cars,
- assign some car to another car,
- again try out the equals() method between both cars,
- drive various distances with some cars and print all the attributes after each trip made.