Question: QUESTION 1 (20 MARKS) Open with Google Docs Given the following CarRental class to store the information about a hotel guest: public class CarRental 1


QUESTION 1 (20 MARKS) Open with Google Docs Given the following CarRental class to store the information about a hotel guest: public class CarRental 1 private String custId; // customer's identification no. private String custName; // customer's name private String carType; // "standard", "premium", "suite" private int numo fHours; // no. of hours of rent public CarRental() ..) public CarRental (String id, String name, String type, int hours) (...) public void setRental (String id, String name, String type, int hours) (...) public String getCustId() {-} public String getCustName() {...} public String getCarType() {...} public int getNumofHours () {...} public String toString() [...] public double calcCharges() {-} // to calculate and return the charges need to be paid by // a customer upon payment a) Write the following method definition: i) Normal constructor for CarRental class (2 marks) ii) Accessor method for each data member (2 marks) toString() method Page 7 / 11 + (2 marks) iii) Method calcCharges() by using information in Table 1 to calculate and return the total charges based on carType. Table 1 Car Type Charged Rate (RM) standard 35 premium 50 suite 70 (4 marks) b) Write a fragment of code in application program that can perform the following tasks: i) Declare an array of object of CarRental class with 100 size. (1 mark) ii) To count and print the number of customer for each room type. (5 marks) iii) To display the most popular room type based on the above counter in b ii) (4 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
