Question: Assignment 4 : Write a Java class named ` Car ` based on the provided ` CarTester . java ` . Requirements for the `

Assignment 4: Write a Java class named `Car` based on the provided `CarTester.java`.
Requirements for the `Car` class:
1. Create a Java class named `Car`.
2. Implement instance variables for the following properties:
- carName,
- mileage
- fuelTankCapacity
- gasLevel
You need to figure out the data types of these variables based on CarTester.java
3. Implement the following methods
- default construcgtor
- overloaded construcgtor
- setters
- getters
- toString()
4. Implement the following additional methods:
drive(distance): This method should allow the car to drive the specified distance. If there's not enough gas, the car should
stop after traveling as much distance as possible.
canDrive(distance): This method should return `true` if the car can drive the given distance with the current gas level,
otherwise `false`.
fillGas(x): This method should fill the car's gas tank with the specified amount `x`. The method should ensure that `x` does
not exceed the available space in the fuel tank and should not allow overflowing.
5. Once you have implemented the `Car` class, test it using the provided `CarTester.java`.
Please do not change CarTester.java
Your Car.java should work with the CarTester.java I provided. Otherwise, you will not earn any credit.
Capture the output produced by `CarTester.java` in a file named `CarTester_output.txt`.
Note: Ensure that the output file (`CarTester_output.txt`) contains the output exactly as produced by running
`CarTester.java`.
Evaluation:
Method or Criteria Points
1 Default constructor 1
2 Overloaded constructor 2
33 Setters 3
43 Getters 3
51 toString() method 4
6 drive() method 4
7 canDrive() method 4
8 fillGas() method 4
Assignment 4 : Write a Java class named ` Car `

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!