Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Car class that has the following fields: year: The year field is an int that holds the car's year. model: The make field

Write a Car class that has the following fields:

year: The year field is an int that holds the car's year.

model: The make field is a String object that holds the model of the car.

speed: The speed field is an int that holds the car's current speed.

instanceNo: The STATIC instanceNo int that is an accumulator to keep track of how many car objects are in the main method.

In addition, the class should have the following methods:

constructor #1: The constructor should accept the car's year and model as arguments. These parameters should be assigned to the object's year and model fields. The constructor should also assign 0 to the speed field. Lastly, it should increment the static field instanceNo by one.

constructor #2: This constructor should make a deep copy of another car and produce a new car that is a carbon copy of the original. Lastly, it should increment the static field instanceNo by one.

accessors: The appropriate accessor methods should be implemented to access all of the instance fields.

accelerate: The accelerate method should add 5 to the speed field when it is called.

brake: The brake method should subtract 5 from the speed field each time it is called.

equals: The equals method should determine if two car objects have equivalent year and model fields.

fastest: A boolean-returning method that returns true if the initial car is going faster (compare two different cars' speeds).

toString: Prints the car's model, year and speed when a car is passed to println().

Create a main method that uses your Car class:

Create three different car objects;

Create a fourth car object that is a carbon copy of your third car -- use the second constructor;

Accelerate cars three and four 3 times;

Print the current speed of all four cars;

Brake your fourth car once, so the third and fourth cars are no longer traveling at the same speed;

Print the current speed of all four cars;

Call the equals method on cars three and four, and print to the end user if they are duplicates (which they should be);

Call the faster method on cars one and four, and print to the end user if car one is going faster than car four.

println() car three.

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_2

Step: 3

blur-text-image_3

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago