Write a Java application that calculates and displays rentals of hiring car for N customers who hire cars from a local car rental company based in Rockhampton, Australia. N should be declared as a constant and should be equal to the largest digit of your student id number (e.g. if your student id is s0705544 then N should be equal to 7). Assume N=4, if the largest digit of your student id number is less than 4.
The standard charges of car rental from this company are shown below in Table 1.
Table 1. The standard charges for car rentals
Days of rental Charge
1 − 5 days $25.0/per day (base rate)
6 − 10 days $22.5/per day
More than 10 days $21.0/per day
The application should ask the user to enter the customer name, the number of days for renting a car, and yes or no to indicate whether the customer receives a special offer or not. The special offer will give customers a 10% discount of the rental no matter how many days they hire a car. Assume that the number of days to be entered is an integer type with the range between 1 and 365. An error message should be issued if a user enters a value beyond this range and the re-entering is required. After entering the above three data items, the program makes a calculation of rental and displays the result as shown in Figure 1. The program should be kept running with entering next set of input data. After all N sets of input data are entered from the keyboard, if the calculation of your program is successfully finished, the execution of your program will also display the information that includes the customer spending most rental, the customer spending least rental as well as a simple statistics bar chart to display how many rents with the number of days are less than 7 days and greater than/equal 7 days in two lines respectively.(Based on historical statistics, most customers hire a car for a period of 7 days). These requirements and the result also can be shown in Figure 2 on next page. Your program should display a similar screen image when it runs. The application should be user-friendly by displaying appropriate welcome, exit and error message. Please note: (1)For simplicity, ignore some complicated factors such as car type, fuel usage, running kilometres in the real-world application. This is a simplified computation model for our purpose of programming exercise. (2)A special offer can be represented by a boolean variable with the value of true/false, or an integer variable with the value of 1 and 0, or a String variable with the value of yes or no (you can use String class built-in method equal( ) to compare two strings); and (3) If the value of N is re-set, your program should be run as normal without changing any source code except setting N with a different value. The application can be implemented in a few of different ways. One of implementations is to use the following classes and methods:
public class CarRental
//declare data members
public CarRental( ) //constructor
public void setName(String n)
public String getName()
public void setDays(int d)
public int getDays()
public double calulateRental()
public void displayInfo()
public class CarRentalTest
public static main(String [ ] args)
//declare data members
// create Scanner object, create a CarRental Object
// use a loop to read data, call methods
This assignment has been answered 5 times in private sessions.
© 2023 Codify Tutor. All rights reserved