You are to develop and test Java classes needed to maintain a collection of vehicles of various type. Vehicles should be able to be added to the collection; reservations should be able to be made,...

1 answer below »

You are to develop and test Java classes needed to maintain a collection of vehicles of various type. Vehicles should be able to be added to the collection; reservations should be able to be made, displayed, and cancelled; and the vehicles should be able to be listed (either all vehicles, or available vehicles for rent).You must use the starter code givenon the last page.



Problem Scenario


Vehicles are identified by a uniqueVIN(Vehicle Identification Number). The set of features maintained for cars, SUVs and trucks are different.Carsare specified as a specific make/model/year, a miles per gallon rating, and seating capacity.SUVsare specified as a particular make/model/year, a miles per gallon rating, seating capacity, and cargo capacity (in sq. ft.).Trucksare specified as a particular length (in feet), a miles per gallon rating, and load capacity (number of rooms of storage).



The list of vehicles that you must use,including the vehicle identification numbers (VINs)providedfor this assignment, is given below. (NOTE: Your output is NOT expected to be lined up as shown below. See middle of page 4 below.)




COSC 237 1 COSC 237 Dierbach Spring 2022 PROGRAM 3 – Vehicle Collections Class Due Tuesday, March 15th by 11:59pm 50 pts. Problem Description You are to develop and test Java classes needed to maintain a collection of vehicles of various type. Vehicles should be able to be added to the collection; reservations should be able to be made, displayed, and cancelled; and the vehicles should be able to be listed (either all vehicles, or available vehicles for rent). You must use the starter code given on the last page. Problem Scenario Vehicles are identified by a unique VIN (Vehicle Identification Number). The set of features maintained for cars, SUVs and trucks are different. Cars are specified as a specific make/model/year, a miles per gallon rating, and seating capacity. SUVs are specified as a particular make/model/year, a miles per gallon rating, seating capacity, and cargo capacity (in sq. ft.). Trucks are specified as a particular length (in feet), a miles per gallon rating, and load capacity (number of rooms of storage). The list of vehicles that you must use, including the vehicle identification numbers (VINs) provided for this assignment, is given below. (NOTE: Your output is NOT expected to be lined up as shown below. See middle of page 4 below.) Make/Model Mileage Seating Capacity VIN CARS Chevrolet Camaro - 2018 30 mpg 2 KH4GM4564GQ Ford Fusion - 2018 34 mpg 4 AB4FG5689GM Ford Fusion Hybrid 32 mpg 4 KV4EG3245RV Chevrolet Impala - 2019 30 mpg 4 RK3MB3366YH Make/Model Mileage Seating Cargo VIN Capacity Capacity SUVs Honda Odyssey - 2020 28 mpg 7 6 cubic ft. VM9RF2635TD Dodge Caravan - 2019 25 mpg 5 4 cubic ft. QK3FT4273NE Ford Expedition - 2018 20 mpg 5 3 cubic ft. JK2HL8264HY Make/Model Mileage Load VIN Capacity Trucks Ten-Foot 12 mpg 2810 lbs. EJ5KU2437BD Eighteen-Foot 10 mpg 5950 lbs. KG4MD5372RK Twenty-Four-Foot 8 mpg 6500 lbs. EB2WR3082OB Twenty-Four-Foot 8 mpg 6510 lbs. TV3GH4390FK Jonathan Amanuel Jonathan Amanuel Jonathan Amanuel Jonathan Amanuel 2 Classes Needed Abstract Vehicle Class instance variables private String description // stores make-model-year for cars and SUVs, stores length for trucks private int mpg // miles per gallon rating private String vin // unique vehicle identification number private Reservation resv // reservation information (a null value means vehicle not reserved) constructor Inits with provided description (description for trucks is just their length (e.g., “Ten-Foot”). Sets resv to null (i.e., newly created vehicles are not yet reserved). h. Methods public String getDescription() { … } public int getMpg() { ... } public String getVIN() { ... } public abstract String toString(); // ABSTRACT METHOD – must be implemented in each subclass public Reservation getReservation() { ... } – throws UnreservedVehicleException if no reservation public boolean isReserved() { ... } public void reserve(Reservation r) { ... } – throw ReservedVehicleException is already reserved public cancelReservation() { ... } - throws UnreservedVehicleException if no reservation Car, SUV and Truck Classes Subclasses of the abstract Vehicle class. Each contains an appropriate constructor, added instance variables, and appropriate implementation of the toString method. Reservation Class instance variables private String name // customer name private String creditCardNum; // credit card number vehicle reserved under private TimeSpan rentalPeriod; // e.g., four days, two weeks, one month private boolean insuranceSelected; // indicates if optional daily insurance wanted methods appropriate constructor, getters and toString methods. Note that reservations cannot be altered once created (i.e., Reservation objects are immutable). TimeSpan Class instance variables private char timeUnit; // ‘D’ (day), ‘W’ (week), ‘M’ (month) private int numUnits; // num of days, weeks or months constructor / getters // appropriate constructor and getters Vehicles Class (collection of Vehicle objects) instance variable private Vehicle[ ] agency_vehicles; // array of Vehicle objects (ArrayList type may NOT be used) private int current // used by iterator methods only methods (appropriate constructor) public void add(Vehicle v) // adds a new vehicle to the collection public Vehicle getVehicle(String VIN) // throws VINNotFoundException if no vehicle found for provided VIN iterator methods public void reset() // resets to first vehicle in list public boolean hasNext() // returns true if more vehicles in list to retrieve pubic Vehicle getNext() // returns next vehicle in list 3 UML Class Diagram Aggregation (collection) Composition Subclass TimeSpan 4 Main Class The main class of the program (with main method) will behave as a test driver for the classes developed. It should be hard-coded to populate a set of vehicles in an object of type Vehicles. This would be done by hardcoding a series of call to the add method of the Vehicles class. The program must provide the following menu of options EXACTLY as given: 1 - Display all vehicles 2 - Display available vehicles 3 - Reserve a vehicle 4 - Display a Reservation 5 - Cancel a Reservation 6 - Add a vehicle 7 - Quit Can display the list of vehicles in the following format, ALL AGENCY VEHICLES Ford Fusion - 2018 (Car) MPG: 34 Seating: 4 VIN: AB4EG5689GM Dodge Caravan - 2019 (SUV) MPG: 25 Seating: 5 Storage: 4 cu. ft. VIN: QK3FT4273ME Eighteen-Foot (Truck) MPG: 10 Load Capacity: 5930 lbs. VIN: KG4DM5472RK etc. AVAILABLE VEHICLES Dodge Caravan - 2019 (SUV) MPG: 25 Seating: 5 Storage: 4 cu. ft. VIN: QK3FT4273ME Eiighteen-Foot (Truck) MPG: 10 Load Capacity: 5930 lbs. VIN: KG4DM5472RK etc. Starter Code You must use the starter code given below. (A download of the starter code is also on Blackboard.) Submission Requirements (1) Submit the .java source files only, as a single zip file. (2) Your name must be on every source file. Otherwise, there will be a 5 point penalty. (3) The version submitted must use the VIN provided for each vehicle. 5 class Main { public static void main(String[] args) { // Declare and populate vehicles collection Vehicles vehs = new Vehicles(); populate(vehs); // Init boolean quit = False; try { // Command loop while(!quit){ displayMenu(); option = input.nextInt(); switch(option) { case 1: displayAllVehicles(); break; case 2: displayAvailVehicles(); break; case 3: reserveVehicle(); break; case 4: displayReservation(); break; case 5: cancelReservation(); break; case 6: addVehicle(); break; case 7: quit = true; } } catch (ReservedVehicleException e) { System.out.println("* Vehicle Already Reserved *"); } catch (UnreservedVehicleException e) { System.out.println("* No Reservation for Vehicle Found *"); } } public static void displayAllVehicles() { vehs.reset(); while(vehs.hasNext()){ System.out.println(vehs.getNext()); // relies on implemented toString() } } public static void reserveVehicle() { // prompt user for vin // prompt for customer name // prompt for credit card num // prompt for how many days, weeks or months (and create TimeSpan object) // prompt for daily insurance option etc. Reservation resv = new Reservation (cust_name, credit_card, rental_period, insur_selected); veh.reserve(resv); } } } PROGRAM
Answered 4 days AfterMar 10, 2022

Answer To: You are to develop and test Java classes needed to maintain a collection of vehicles of various...

Arun Shankar answered on Mar 12 2022
117 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here