Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class named Car to represent a car. The class should have the following data fields (name each data field appropriately): A private string

Design a class named Car to represent a car. The class should have the following data fields (name each data field appropriately):

A private string data field to specify the make of the car (the default is "Make")

A private string data field to specify the model of the car (the default is "Model")

A private int data field to specify the year of the car (the default is 2018)

A private double data field to specify the cost of the car (the default is 30,000)

A private string data field to specify the color of the car (the default is "White")

The class should have the following methods:

Accessor and mutator methods for all data fields

A no-arg constructor that creates a default car

A constructor that takes in values for all five data fields and sets them

A method named toString() that returns a string description for the car

Draw the UML diagram for the Car class and implement the class. Write a test program (separate class, but can be in the same file) that creates two cars:

Car 1

Create this car using the no-arg constructor

Use the appropriate mutator method to set the car's make to "Toyota"

Use the appropriate accessor method to display the car's new make value

Use the appropriate mutator method to set the car's model to "Highlander"

Use the appropriate accessor method to display the car's new model value

Use the appropriate mutator method to set the car's cost to $31,695

Use the appropriate accessor method to display the car's new cost value

Car 2Create this car using the constructor that accepts values

Make: Kia

Model: Optima

Year: 2016

Cost: $22,500

Color: Red

Print out the values for Car 2 using the toString() method

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

3 > O Actual direct-labour hours Standard direct-labour hours...

Answered: 1 week ago