Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve Problem 2 based on the info provided before it. It should have 3 classes and done in Java. There is a car rental company

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Solve Problem 2 based on the info provided before it. It should have 3 classes and done in Java.

There is a car rental company that would like to update their system with a new feature that can check if current fuel level is sufficient for the customer to drive to the destination and keep track of the cars if they need to be refilled after several trips. We read the instructions from the standard input (console/keyboard). The program will start from the main method in the Main. java file. Each object from the class CarModel is supposed to represent a certain car model with the given name, fuel economy, and tank capacity. Each object from the class Car is an instance of a car from a given model and with a certain plate number. The cars can go on a trip, and they will consume some fuel based on the length of the trip and the fuel economy of their models. Cars can be refilled after they run out of fuel. Input As shown in the following examples, each line of input is a command with multiple space-separated tokens: - If the line starts with "MODEL," then it is defining a new car model, and it will be followed by the model name (comprised of English characters or digits with no spaces in between), fuel economy (floating point value), and tank capacity (floating point value). - If the line starts with "CAR," then it defines an instance of a car, and it will be followed by the model name and the plate number (plate number is always a positive integer smaller than 999999). - If the line starts with "TRIP," then it will be followed by a plate number and given distance in kilometers. In this case, the car will burn some gas and the program should output whether the trip was successful (see the output sample for details). - If the line starts with "REFILL," then it will be followed by a plate number. In this case the fuel tank of the corresponding car should be refilled to be full. - If "FINISH" is written on a line, it signals the end of the input. - You can assume that the maximum number of commands is 100 . This can help you in creating appropriate arrays (you can also use ArrayLists to handle a case where you do not know the size of an array a priori). Examples Here is a different example with the use of REFILL command. Processing Your program should be able to keep track of the trips to see if the trip for the car is successful or not. Assume every car has a full tank of fuel at the beginning of its first trip. Fuel consumption is calculated by 100.0distance fuel economy Apart from keeping track of the trips, your program should also have a refill function with the following assumptions. - Your program should accommodate the input with some leading spaces and following spaces if the inputs have some extra spaces. - You can assume that we will not have multiple "MODEL" commands with the same model name. Also, we will not have multiple "CAR" commands with the same plate number. - You can assume that the input is always in the correct format. Also, there are no "TRIP" or "REFILL" commands where the plate number is not defined before. Also, there is no "CAR" command where its model name is not defined before. - Input starting with "REFILL" means the gas tank of the corresponding car should be refilled to be full. - The commands are run line-by-line so the order of the input (and output) matters. - You are allowed to create new classes, use the given classes, and modify the given classes. Your final main () function should be defined within the class Main. Problem 2: Car Rental with Trip Comparison Extend your program from Problem 1 to handle one more change. We build on Problem 1 and add the following commands to the set of possible commands. Input Based on the input of Problem 1, there is one additional function that we need to cover. If an input line starts with "LONGTRIPS," then it will be followed by a plate number and a distance in kilometers (floating point). Processing Your program should perform the same task as stated in Problem 1. In addition, in the case of input line starting with "LONGTRIPS," you will need to output the number of trips that were made successfully by the given car and were equal or longer than the given distance. See the example output for details. Output The output format is shown in the following examples

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions