logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

How many vehicles do you want to create?

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Description

Assignment 2 will extend the midterm – please use the sample solution for the midterm as your starting point. Instead of having the available vehicles hard-coded in the source code, at program startup, the user should be given two choices: 1) to enter the available vehicles, or 2) to load the available vehicles from a file. If the user chooses option 1, the program should prompt the user for the number of vehicles to enter, and then allow the user to enter the details of the chosen number of vehicles. The program should then create a Vehicle array with the entered values and store the content of that array into a file called NewVehicles.txt. If the user chooses option 2, they program should ask for a file name, and then load the vehicles from that file and insert them into a Vehicle array. Now, irrespective of which choice the user made, the program should continue as before, by displaying the choice of vehicles from the array and allowing the user to create a rental.

Required File Format

 

The file to store vehicles must have the following structure: The first line contains the number of vehicles. After this, for each vehicle, the first line indicates the type of vehicle (Car or Truck), followed by lines for the model, the rate and finally the size or cargo capacity (depending on

 

whether it is a car or a truck). In other words, for each vehicle, the file should contain four lines. The following is an example of a file with three vehicles – a car followed by a truck followed by another car:

3

Car

Toyota Yaris 50.0 COMPACT

Truck Ford F150 120.0

8500.0

Car

BMW 750i 199.0 PREMIUM

 

The file to store to or load from should be located in the src folder of your Eclipse project. To access a file in that folder, use a relative path, similar to the following code example:

Path file = Paths.get("src\\" + fileName);

 

Sample Runs of the Program

 

Sample run 1 – user chooses to enter vehicles

 

Please choose from the following options:

1 - Enter Vehicles

2 - Load Vehicles 1

How many vehicles do you want to create? 2

Enter 1 for Car and 2 for Truck: 1

Enter model:

Honda Civic Enter rate:

49.99

What is the size of this car?

1 - COMPACT

2 - MIDSIZE

3 - FULLSIZE

4 - PREMIUM

Please enter your choice: 1

Enter 1 for Car and 2 for Truck: 2

Enter model:

Dodge Ram

 

Enter rate:

99

Please enter the cargo capacity:

5000

Successfully written 2 vehicles. Available vehicles:

1 COMPACT Honda Civic - Daily rate: $49.99

2 TRUCK with cargo capacity: 5000.0kg. Dodge Ram - Daily rate: $99.0 Pick a vehicle by entering its number:

1

Please enter the pick up date:

Please enter year:

2023

Please enter month:

4

Please enter day:

1

Please enter the drop off date:

Please enter year:

2023

Please enter month:

4

Please enter day:

5

Rented vehicle:

COMPACT Honda Civic - Daily rate: $49.99 Pick up date: 2023-04-01

Drop off date: 2023-04-05 Rental rate: $199.96

 

Note that after this run, there should be a file called NewVehicles.txt in the src folder of the project with exactly the following content:

 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

961 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

718 Answers

Hire Me
expert
Husnain SaeedComputer science

882 Answers

Hire Me
expert
Atharva PatilComputer science

629 Answers

Hire Me

Get Free Quote!

335 Experts Online