Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please I need help with this Java program! Writing it using a try and catch. Thank you! Car Program *: Your uncle is trying to

Please I need help with this Java program! Writing it using a try and catch. Thank you!

Car Program *:

Your uncle is trying to keep track of his new-car and used-car lots by writing a Java program. He needs your help in setting up his classes.

Implement a superclass named Car that contains a price instance variable, a getPrice method, and a 1-parameter constructor. The getPrice method is a simple accessor method that returns the price instance variables value. The 1-parameter constructor receives a cost parameter and assigns a value to the price instance variable based on this formula:

price = cost * 2;

The NewCar and UsedCar classes should each contain a 2-parameter constructor, an equals method, and a display method. In the interest of elegance and maintainability, dont forget to have your subclass constructors call your superclass constructors when appropriate. The display method should print the values of all the instance variables within its class.

Provide a driver class that tests your three car classes. Your driver class should contain this main method:

public static void main(String[] args)

{

NewCar new1 = new NewCar(8000.33, "silver");

NewCar new2 = new NewCar(8000.33, "silver");

if (new1.equals(new2))

{

new1.display();

}

UsedCar used1 = new UsedCar(2500, 100000);

UsedCar used2 = new UsedCar(2500, 100000);

if (used1.equals(used2))

{

used1.display();

}

} // end main

Output:

price = $16,000.66, color = silver

price = $5,000.00, mileage = 100,000

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions