Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE Eclipse IDE for java Java program Create a package named lab (no spaces, ALL in lowercase) where you will place your lab files Write

image text in transcribed
USE Eclipse IDE for java Java program Create a package named lab (no spaces, ALL in lowercase) where you will place your lab files Write a class named Car with the following fields: year - The year field is an int that holds the car's year. make - The make field references a String object that holds the make of the car. model - The model field references a String object that holds the model of the car. speed - The speed field is an int that holds the car's current speed rpm- The rpm field is an double that holds the car's current RPM. In addition, the class should have the following constructor and other methods: Constructors. The custom constructor should accept the year, make, and model as arguments. These values will be assigned to the object's year, make, and model fields. The constructor should also assign 0 to the speed field and a random number between 0 and 8 to the rpm field. Your class should also support a default constructor that sets fields to Java's default values (0 for numbers, null for references). Accessors methods. Appropriate accessors methods should be implemented to get the values stored in an object's year, make, model, speed, and rpm fields. Mutators methods. Appropriate mutator methods should be implemented to set the values stored in an object's year, make, model, speed, and rpm fields. accelerate. The accelerate method should add 1 to the speed field each time it is called. It should also generate a random number between 0 and 8 and assign it into the rpm field. brake. The brake method should subtract 1 from the speed field each time it is called. Demonstrate the use of your class by creating program called CarApp that creates a Car object and then ask the user how many miles to accelerate. Then invoke the accelerate method as many times as the user indicates (e.g. if the user selects 15, invoke accelerate 15 times). After each call to the accelerate method, get the current speed of the car and display it a message indicating the year, make, model, speed, and rpm (e.g. "2020 Toyota Camry current speed is 22 MPH at 3.8 RPM"). Then call the brake method 5 times. After each call to the brake method, get the current speed of the car and display a similar message as in the previous step (e.g. 2021 Tesla Model S current speed is 37 MPH at 2.1 RPM")

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions