IT 168 Fall, 2025 Pierce Programming Assignment 4 Due Date: Oct 29th, 2025 by 11:55pm This assignment is worth 100 points. In this assignment you are asked to model and design an CarRental System and write a program to test your design by creating objects and calling methods, and using all the programming concepts you have learned so far. You are asked to write the following classes: The CarRentalListing Class Design a UML class diagram and write the java code for a CarRentalListing class to hold the relevant data and behavior of car rental listing objects. The CarRentalListing class must be defined in its own file named CarRentalListing.java. Class Fields: your class should have the following fields: Static/class variables: o A static class variable/field totalListings that keeps track of how many car rental listing objects have been created (0 by default). o Three static constants namely Fuel fee $42.00 Service fee $12.55 Tax $13.00 Instance variables: o Rental Code: A unique 4-character alphanumeric code for each car rental listing. o City: The rental city (e.g., “Normal”). o Car Model/Name: Car name (e.g., “Toyota Corolla”). o Car Type: Type of car (e.g., Sedan, SUV, Coupe). o Price per Day: The rental price per day. o Minimum Rental Days: Minimum number of days required to rent the car. o Requested Rental Days: Number of days requested for renting the car. o Confirmation Code: A 6-character alpha numeric unique confirmation code for each booking of the listing. You should select the appropriate data type for each field above. Make all instance variables and constants private and make the static class variable public. Constructors: the class should have the following constructors: A default constructor that o Increments totalListings by 1 o Sets everything else to default values based on data type A constructor that receives the car model, type, city, price as parameters o the constructor should call the default constructor using chaining o then it should initialize the corresponding instance variables with the passed parameters. o Then, it should call the following methods in order: calcMinimumRentalDays(CarType) method by passing the car type as a parameter. generateListingCode method Methods: The class should have the following private methods A private method calcMinimumRentalDays that takes the car type as a parameter and initializes the minimum rental days variable as follows: Car type Sedan SUV Coupe Van Min rental days 1 2 3 4 A private generateListingCode method that generates a code according to the following algorithm: o Concatenates the first character of the city, the first character of the car model/name, first character of car type, and the latest total listing count (e.g., "CHS1"). o The method does not return any value. It just assigns the generated code to the rental code instance variable. A private generateConfirmationCode method that generates a confirmation code according to the following algorithm: o Generates a 4-digit random number o Concatenates the first character of the car name, the last letter of the listing city, the first letter of the type, and the 4 digit number. For example, if car name is Honda City, city is “Chicago”, and type is Sedan, the generated confirmation code would be HoS8944. The method does not return any value. It just assigns the generated code to the confirmation code instance variable. The CarRentalListing class should have the following public methods. Getters and setters for the instance variables: car model, type, city, price, minimum and requested rental days. A toString method that returns a String with the car rental listing object’s information. The method should take care of formatting the output. Below is a sample output when toString method is called on 4 listing objects. You can use tab (\t) to format the output. Code CHS1 NTS2 BTV3 PFC4 Car Name Honda City Tesla Model Y Toyota Sienna Ford Mustang City Chicago Normal Bloomington Peoria Type Sedan SUV Van Coupe Price $15.99 $20.99 $17.99 $18.99 bookRental method that takes the number of requested days as a parameter. o The method should check the minimum days and return an appropriate error message if the requested days violate the minimum. o Otherwise, the method should call the generateConfirmationCode method o The method then calls the calculateTotalPrice method which calculates and returns the total price of the listing based on the number of requested days, adding the fees and taxes. It takes number of requested days as parameter, and displays the following summary: Confirmation code: HoS8944 Summary of your reservation: City: Chicago Rental Type: Sedan (Honda City) Pick-up: after 5:00pm Drop-off: by 10:00pm Total (USD) $76.54 o The method then calls the displayReceipt that takes number of requested days and total price as parameters, and prints a receipt as follows: Price breakdown $15.99 x 1 day Fuel fee Service fee Taxes Total (USD) $15.99 $35.00 $10.55 $15.00 $76.54 The Driver class (TestCarRentalListing) Write a program that does the following: 1. Creates the following four listing objects, each of the class type CarRentalListing, in the main method: CarRentalListing listing1 = new CarRentalListing (“Honda City”, “Sedan”, “Chicago”, 15.99); CarRentalListing listing2 = new CarRentalListing (“Tesla Model Y”, “SUV”, “Normal”, 20.99); CarRentalListing listing3 = new CarRentalListing (“Toyota Sienna”, “Van”, “Bloomington”, 17.99); CarRentalListing listing4 = new CarRentalListing (“Ford Mustang”, “Coupe”, “Peoria”, 18.99); 2. Then, the program should print a welcome message and display the following menu. Create a static method called displayMenu() inside the TestCarRentalListing class and call this method from the main method. Please choose one of the following: L – list available rentals LC – list available rentals by city LT – list available rentals by type LP – list available rentals by price B – book a listing Q – quit When the user selects option L, the program should display all the listings. When the user selects option LC, the program should prompt user to input city. When the user selects option LP, the program should prompt user to input price. This price should represent the maximum price per day for a vehicle rental. When the user selects option B, the program should call the displayReceipt method from the CarRentalListing class. When the user selects option LT the method should provide a follow up prompt: What type of car are you looking for? 1 - Sedan 2 – SUV 3 – Coupe 4 - Van 3. The menu should keep repeating until the user chooses to quit. Make sure to perform user input validation on the menu options, listing number, type. You can assume user is entering the correct data types. See sample outputs below: Sample output (user input in red): Welcome to our Car Rental System! Please choose one of the following: L – List available rentals LC – List rentals by city LT – List rentals by type LP – List rentals by price B – Book a rental Q – Quit a Invalid input Please choose one of the following: L – List available rentals LC – List rentals by city LT – List rentals by type LP – List rentals by price B – Book a rental Q – Quit Enter your choice: 2 Invalid input Please choose one of the following: L – List available rentals LC – List rentals by city LT – List rentals by type LP – List rentals by price B – Book a rental Q – Quit Enter your choice: l Code Car Name CHS1 Honda City NTS2 Tesla Model Y JTV3 Toyota Sienna PFC4 Ford Mustang City Chicago Normal Joliet Peoria Please choose one of the following: L – List available rentals LC – List rentals by city LT – List rentals by type Type Sedan SUV Van Coupe Price 15.99 20.99 17.99 18.99 LP – List rentals by price B – Book a rental Q – Quit Enter your choice: LC What city? : Louisville All cars in Louisville: Code Car Name City Not a valid city Type Price Type Sedan Price 15.99 Please choose one of the following: L – List available rentals LC – List rentals by city LT – List rentals by type LP – List rentals by price B – Book a rental Q – Quit Enter your choice: LC What city? : Chicago All cars in Chicago: Code Car Name CHS1 Honda City City Chicago Please choose one of the following: L – List available rentals LC – List rentals by city LT – List rentals by type LP – List rentals by price B – Book a rental Q – Quit Enter your choice: lp What maximum price are you looking for? $20 All cars $20.0 or less: Code Car Name City CHS1 Honda City Chicago JTV3 Toyota Sienna Joliet PFC4 Ford Mustang Peoria Please choose one of the following: L – List available rentals LC – List rentals by city Type Sedan Van Coupe Price 15.99 17.99 18.99 LT – List rentals by type LP – List rentals by price B – Book a rental Q – Quit Enter your choice: b For which listing? NTS2 How many days would you like? 3 Booking successful! Confirmation code: TlS7723 Summary of your reservation: City: Normal Rental Type: SUV (Tesla Model Y) Pick-up: after 5:00 pm Drop-off: by 10:00 pm Total (USD): $130.22 Price breakdown: $20.99 x 3 day(s) $62.97 Fuel Fee $42.00 Service Fee $12.25 Tax $13.00 Total (USD) $130.22 Please choose one of the following: L – List available rentals LC – List rentals by city LT – List rentals by type LP – List rentals by price B – Book a rental Q – Quit Enter your choice: q Goodbye! Submission Instructions You will submit the following: 1. your UML diagram for the CarRentalListing class as a pdf file. 2. A compressed .zip archive with two .java files, corresponding to the CarRentalListing and TestCarRentalListing classes. Remember, a. The class name should match the .java file name. b. Each .java file must start with the two beginning comment blocks as specified in the coding guidelines for this course (on Canvas). c. All public methods should be well commented with Javadoc comments d. You should use meaningful variable names that follow the Java naming conventions. Grading Criteria Design (7 points) UML Class diagram for the CarRentalListing o Correct notation o fields show access modifier, data type, and name; o methods include method name, parameters with data type, and return type. Processing Logic (93 points) Driver class o (5) The main() method is as clean as possible and handles the menu inside a separate method. o (2) Displays a welcome greeting o (3) Creates specified objects to hold listing info correctly o (8) Correct display of menu options with appropriate formatting, and by calling the displayMenu() method. o (2) Display menu keeps repeating and does not run only once o (10) Handle the different choices from the menu by calling appropriate methods including follow up prompts. o (2) Program quits correctly when “Q” is selected o (5) Handles input validation on menu options, listing number, type, as well as input mismatch issues. o (6) Displays listing info correctly with proper formatting and using toString() User defined class o (5) Differentiates between instance variables, constants and static variables correctly o (6) Correct data types of variables o (6) Constructors work correctly o (5) calcMinimumDays works correctly o (5) generateListingCode works correctly o (3) generateConfirmationCode works correctly o (5) displayReceipt() works correctly o (6) bookListing works correctly o (5) calculateTotalPrice method works correctly (2) Correct return types/ argument types of methods (2) correct use of static, final, and access modifiers (public/Private) Deductions Late (10% per calendar day) (-30) Syntax Errors (-30) Runtime Errors (-2 for each) Violation of any of the following Style and Organization criteria: o Well written Javadoc comment blocks at class level and at method level o Formatted code: Properly spaced and indented Naming conventions o No redundant code o Submits .java files, not .class files o All 3 files zipped correctly according to directions
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )