[B]I need to finish this assignment can someone help me plz.
The Car Class
The purpose of this assignment is to learn how to write your own class that serves as a template for creating objects. The Car class represents an automobile. Each car has a color, miles driven, and the amount of gasoline in the tank (gallons).
The Car class should have both a default and parameterized constructor. The default constructor should initialize all of the instance variables. (The default miles driven and gallons should be zero.) The parameterized constructor will accept a color parameter. Each constructor should call the private method drawShape() that creates the car. (The car's shape does not need to be elaborate.)
Write the methods described here:
drawShape is a private method that creates the GCompound representing the car
setColor accepts a color parameter and sets the color of the car
drive accepts miles and speed as parameters. Miles must be greater than zero. Speed must be between 0 and 100. As long as the car has gas in the tank, add the miles to the car's total miles, and reduce the amount of gasoline based on the miles per gallon, which can be estimated using the following formula:
miles per gallon = 55 - speed/2
getMilesDriven returns the number of miles the car has driven
fill accepts an amount of gas as a parameter and adds it to the car's gallons; the amount must be greater than zero
isEmpty returns true if the car's tank is empty, and false if it is not
toString returns a String containing the car's miles driven and gallons in the tank
The UML class diagram for the Car class is displayed on the right. Do not create any instance variables or methods other than those shown.
To test your Car class, create an Applet called TestDrive that extends GraphicsProgram . Create and display three cars. Use each of your constructors at least once. Fill each tank and drive each car. Then, below each car, print its information using the toString() method. (Your cars do not need to move in this assignment.)
Sample output is shown here:
Have fun!
Car
_______________ _________
- color
- miles driven
- gallons
_______________ _________
+ Car()
+ Car(color)
- drawShape()
+ setColor(color)
+ drive(miles, speed)
+ getMilesDriven( )
+ fill(amount)
+ isEmpty()
+ toString()
The Car Class
The purpose of this assignment is to learn how to write your own class that serves as a template for creating objects. The Car class represents an automobile. Each car has a color, miles driven, and the amount of gasoline in the tank (gallons).
The Car class should have both a default and parameterized constructor. The default constructor should initialize all of the instance variables. (The default miles driven and gallons should be zero.) The parameterized constructor will accept a color parameter. Each constructor should call the private method drawShape() that creates the car. (The car's shape does not need to be elaborate.)
Write the methods described here:
drawShape is a private method that creates the GCompound representing the car
setColor accepts a color parameter and sets the color of the car
drive accepts miles and speed as parameters. Miles must be greater than zero. Speed must be between 0 and 100. As long as the car has gas in the tank, add the miles to the car's total miles, and reduce the amount of gasoline based on the miles per gallon, which can be estimated using the following formula:
miles per gallon = 55 - speed/2
getMilesDriven returns the number of miles the car has driven
fill accepts an amount of gas as a parameter and adds it to the car's gallons; the amount must be greater than zero
isEmpty returns true if the car's tank is empty, and false if it is not
toString returns a String containing the car's miles driven and gallons in the tank
The UML class diagram for the Car class is displayed on the right. Do not create any instance variables or methods other than those shown.
To test your Car class, create an Applet called TestDrive that extends GraphicsProgram . Create and display three cars. Use each of your constructors at least once. Fill each tank and drive each car. Then, below each car, print its information using the toString() method. (Your cars do not need to move in this assignment.)
Sample output is shown here:
Have fun!
Car
_______________ _________
- color
- miles driven
- gallons
_______________ _________
+ Car()
+ Car(color)
- drawShape()
+ setColor(color)
+ drive(miles, speed)
+ getMilesDriven( )
+ fill(amount)
+ isEmpty()
+ toString()
Comment