Question: In java: Code into java a class, Car, which consists of a constructor and several methods. The Car class is to be used for a
In java:
Code into java a class, Car, which consists of a constructor and several methods. The Car class is to be used for a Car Hire Company and the data to be stored consists of:
The make of the car
The model of the car
The cars registration number
Whether the car is on hire or not
The name of the hirer (if it is on hire)
The methods in Car:
1-Car(String newMake, String newModel, String newRego)
Constructor, stores the make, model and registration number of the new car and sets its status as available for hire.
2-boolean hire(String newHirer)
Hire this car to the named hirer and return true. Returns false if the car is already out on hire.
3-boolean returnFromHire()
Receive this car back from a hire and return true. Returns false if the car was not out on hire.
4-String getRego()
Accessor method to return the cars registration number
5-boolean hireable()
Accessor method to return the cars hire status. Return true if the car is available for hire and return false if it is already out on hire.
6-String toString()
Return the cars details as a formatted String. The output should be a single line containing the make, model and registration number, followed by the statement either
Available for hire
or
On hire to:
followed by the name of the hirer.
Code the driver class to test that the methods in the Car class are working correctly;
7-Create 3 Car objects
8-Hire the first car and print a statement showing its registration number and that it has been hired
9-Repeat steps for the second car
10-Write code to check whether each of the 3 cars is available and hire the car which is available
11-Return the first car and print a statement showing its registration number and that it has been returned
12-Use the toString method to print the details of the 3 cars
Output code should resemble the following:
Car Reg: 12345 has been hired
Car Reg: 12345 has been returned
Make: Honda Model: Civic Reg: 12345 Status: Available
Make: Toyota Model: Corolla Reg: 56789 Status: On Hire to: John
Make: Isuzu Model: Trooper Reg: 452784 Status: On Hire to: David
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
