Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 (12 pts) Write a class named car that represents a car. Your car class should have the following: Instance variables (2 pts o

image text in transcribed

image text in transcribed

Problem 1 (12 pts) Write a class named car that represents a car. Your car class should have the following: Instance variables (2 pts o o o o Make and model of the car Color of the car The car's price The car's mileage (total miles traveled, not miles per gallon) .Two overloaded constructors (2 pts) A constructor that takes no parameters. This constructor should set the mileage to 0 and set some default values (use whatever you want) for the make, model, color, and price. A constructor that allows you to set values for the make, model, color, and price. This constructor should also set the mileage to 0. o o Methods (I pt each o public void setPrice (double p) o public void paint (String c) o public void diaplayCarIntof) This should update the instance variable for price with the specified value. This should "paint" the car by changing the instance variable for color with the specified value. This should display all available information on the car, including its make, model, color, price, and mileage o public void travel (double distance) This should display a message saying that the car is traveling for the specified distance. This method should also increase the value of the mileage attribute accordingly Once you've finished your car class, write a separate client program named carclient containing a main method (4 pts) that does the following actions: Create two new car objects: a black Porsche Cayman S with a price of $63,800, and a blue Nissan Leaf with a price of $29,010. (If you'd like to buy me one of the former - preferably with a manual transmission - I'll consider a few extra credit points)

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

More Books

Students also viewed these Databases questions

Question

6. The cost of the training creates a need to show that it works.

Answered: 1 week ago