Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objective: In this assignment you will brush up on Java fundamentals by creating an application that collects and models basic information about a car. The
Objective:
In this assignment you will brush up on Java fundamentals by creating an application that collects and models basic information about a car. The assignment involves most of the topics covered in IST namely:
fundamental datatypes int boolean, double, string, etc.;
statements and control structures assignments calls, conditionals, and loops;
primitive collections arrays and usage of basic data structures arraylists;
definition and use of static methods;
basic inputoutput IO and exception handling via trycatch.
Getting Started:
To get started, create a new IntelliJ project named asgto stay organized, I recommend storing the projects folder within your 'assignments' folder for the course Once the project is created, right click the blue src folder click 'New' then click 'package'. Next, add a package called 'edu.psu.ist'.
If you need assistance creating packages or need a refresher on them, consult the recording on packages under M Java review.
Part : Adding car information input methods
Whichever car you choose to model, certain information about it will need to be input such as its makemodel year released must be a positive number trim, MPG must be positive and the type of car restrict this to: Truck, Sedan, Coupe, Station Wagon, or Van
Think carefully about appropriate datatypes for the information listed, then start by adding a static method to:
Prompt for the model of the car and return what was entered by the user. You'll need to use the Scanner class to read this in eg Corolla, RAV Camry, etc. are some examples
Now add a main method and call the method written above and ensure that it works. TIP: after writing each method detailed below, call it from the main to ensure it works don't write ALL the code and then run it take it one method at a time and don't proceed until you get it working
Next, add static methods to:
Prompt for the car's release year; keep prompting until the user has entered a valid year ie: can't be or negative Once a valid year is entered, return it
Prompt for the car's trim and return it; note that 'trim' is a car manufacturer label indicating which features are included in the car for example: DX LX WRX Sport, etc. are some sample trims The user should be able to enter as many of these as they like including and the application should store each one. This should suggest a certain datatype hint: don't pack them all into a single string
Prompt for the type of car; acceptable inputs for the car type include: Truck, Sedan, Coupe, Station Wagon, or Van. If the user doesn't input one of these, keep prompting until they enter one of the types listed. Once a valid car type is entered, return it Consider using an enum datatype to represent the valid types of cars this is not required for this assignment
Prompt for the car's MPG miles per gallon; keep prompting until the user enters a valid nonnegative input then return it
Make sure you've called each of the above methods in the order in which they are described above from the main they should only be called from the main method
If a given method returns a value, save it in a local variable within the main.
Part : Saving and printing car information
Lastly, add the following static methods these should only be called from the main method:
combine, which takes as input all the information returned from the previous methods and and returns it all in a single string in the string this method returns, each piece of information should be separated by a newline
write, which takes a string containing the combined information returned from the above method and writes this string to a file called 'car.txtuse exception handling ie: trycatch
read, reads the contents of the 'car.txt file line by line, printing out each line using System.out use exception handling
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started