you have developed programs for Cost Is No Object—a car rental service that spec
ID: 3629864 • Letter: Y
Question
you have developed programs for Cost Is No Object—a car rental service that specializes in lending antique and luxury cars to clients on a short-term basis. Create a class whose main() method assigns cars and rental fees to customers for the current day. The program continuously prompts for input data until the user indicates the end of the data has been reached.Input data includes the following:
· Customer name
· Code for desired car type—A for Antique Car or L for Luxury Car
· Number of days for the rental
In the main() method, create four parallel arrays. The first three contain car descriptions, daily rental fees, and the car-type code, as follows:
Description
Daily Fee
Code
1967 Ford Mustang
$65
A
1922 Ford Model T
$95
A
2008 Lincoln Continental
$135
L
2002 Lexus
$140
L
2007 BMW
$160
L
1910 Mercer Runabout
$165
A
2009 Mercedes Benz
$200
L
1930 Cadillac V-16
$205
A
The fourth array contains an indicator that specifies whether the car is already rented. At the start of the program, none of the cars is rented.
After the user is prompted for the first customer’s data, pass the customer’s name, car type requested, and the four arrays of data to a method named fulfillRequest(). The method finds the first available car of the correct type, displays its description and rental fee, and changes the rental indicator to show the car is no longer available. If no cars are available of the type requested by the customer, display an appropriate message. The method returns the daily rental fee unless no cars of the correct type are available, in which case the method returns 0. The main() method displays the daily rental fee.
If a car of the correct type is available, the main() method should pass the daily rental fee, the number of rental days, and the car type requested to a method named calculateContractAmount(). The contract amount is the daily fee times the number of days plus tax. The tax is 6 percent of the rental price for an antique car and 8 percent of the price for a luxury car. The method returns the amount of the contract to the main() method, where it is displayed.
Before the user is prompted for data for any customer after the first one, determine whether any cars are still available for rent. If no more cars are available, display an appropriate message and end the program
Explanation / Answer
For this application we have stored some model names, their registration no, rent rate on the basis of per day, and the amount to deposit in the arraylist. import java.util.*;class Car { private String make; private String model; private String regNo; private int deposit; private int rate; public Car(String newMake, String newModel, String newRegNo, int newDeposit, int newRate) { make = newMake; model = newModel; regNo = newRegNo; deposit = newDeposit; rate = newRate; } public String getMake() { return make; } public String getModel() { return model; } public String getRegNo() { return regNo; } public int getDeposit() { return deposit; } public int getRate() { return rate; }}public class TestProject { public static void main(String args[]) { List carlist = new ArrayList(); carlist.add(new Car("Toyota", "Altis", "SJC2456X", 100, 60)); carlist.add(new Car("Toyota", "Vios", "SJG9523B", 100, 50)); carlist.add(new Car("Nissan", "Latio", "SJB7412B", 100, 50)); carlist.add(new Car("Murano", "SJC8761M", "Nissan", 300, 150)); carlist.add(new Car("Honda", "Jazz", "SJB4875N", 100, 60)); carlist.add(new Car("Honda", "Civic", "SJD73269C", 120, 70)); carlist.add(new Car("Honda", "Stream", "SJL5169J", 120, 70)); carlist.add(new Car("Honda", "Odyssey", "SJB3468E", 200, 150)); carlist.add(new Car("Subaru", "WRX", "SJB8234L", 300, 200)); carlist.add(new Car("Subaru", "Imprezza", "SJE8234K", 150, 80)); Scanner input = new Scanner(System.in); System.out.print("Enter model to rent: "); String model = input.nextLine(); for (Car s : carlist) { if (model.equals(s.getModel())) { System.out.println("Model " + model + " is available"); System.out.print("Enter number of days: "); int days = input.nextInt(); System.out.println("***************Details*****************"); int cost = (days * s.getRate()) + s.getDeposit(); System.out.println("Deposit DailyRate Duration TotalCost"); System.out.println(s.getDeposit() + " " + s.getRate()+ " " + days + " " + cost); System.out.print("Proceed to rent?( y/n ): "); String dec = input.next(); if (dec.equals("y")) { System.out.println("Enter Customer Name: "); String name = input.next(); System.out.println("Enter IC Number: "); int num = input.nextInt(); System.out.println("************Receipt*************"); System.out.println("Name ICNo Car RegNo Duration TCost"); System.out.println(name + " " + num + " " + model + " " + s.getRegNo() + " " + days + " "+cost); System.out.println("Serving Next Customer "); } else if (dec.equals("n")) { System.out.println("Serving Next Customer: "); } } } }}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.