Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSCI 1110: Assignment 2 Due: 2:00 pm, Monday, February 27, 2023 The purpose of this assignment is to reinforce your understanding of object-based programming and

CSCI 1110: Assignment 2 Due: 2:00 pm, Monday, February 27, 2023 The purpose of this assignment is to reinforce your understanding of object-based programming and to problem-solve using objects, classes, and nested loops. For this problem you will be provided with sample tests in Codio. All input is done via the console and all output is to be done to the console as well. You must submit your assignment via Codio, and you can test it by submitting your code. Note: for this assign- ment you are expected to install and use an IDE (other than Codio) to develop your code. Please see How-To videos in the How-To Tutorial Section of our Brightspace page on how to install an IDE. This assignment is divided into two problems, where each problem subsumes the previous one. Hence, if you complete Problem 2, you will have also completed Problem 1. Problem 1: Car Rental with Refill 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/key- board). 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 to- kens: 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 Input Output MODEL Camry 6.5 58 MODEL Civic 7.5 52 CAR Camry 1111 CAR Camry 2222 CAR Civic 3333 CAR Civic 4444 TRIP 1111 350 TRIP 2222 350 TRIP 3333 350 TRIP 4444 350 TRIP 1111 350 TRIP 2222 350 TRIP 3333 350 TRIP 4444 350 FINISH Trip completed successfully for #1111 Trip completed successfully for #2222 Trip completed successfully for #3333 Trip completed successfully for #4444 Trip completed successfully for #1111 Trip completed successfully for #2222 Not enough fuel for #3333 Not enough fuel for #4444 Here is a different example with the use of REFILL command. Input Output MODEL X5 10 68 CAR X5 787878 TRIP 787878 500 TRIP 787878 500 TRIP 787878 10 REFILL 787878 TRIP 787878 500 FINISH Trip completed successfully for #787878 Not enough fuel for #787878 Not enough fuel for #787878 Trip completed successfully for #787878 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.0 . 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 RE- FILL 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.

Output If the current fuel level for the car with plate number is enough for a trip, it will output the trip completed successfully for the car with corresponding plate number; otherwise, print out not enough fuel for the car with corresponding plate number. All output should be to the console, and each line is terminated by a newline. The output format is shown in the above 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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago