Modify the Car class example and add the following:  A default constructor that initializes strings to “N/A” and numbers to zero.  An overloaded constructor that takes in initial values to set your fields (6 parameters). accel() method: a void method that takes a double variable as a parameter and increases the speed of the car by that amount. brake() method: a void method that sets the speed to zero.  To test your class, you will need to instantiate at least two different Car objects in the main method in the CarDemo class.  Each of your objects should use a different constructor. For the object that uses the default constructor, you will need to invoke the mutator methods to assign values to your fields. Invoke the displayFeatures() method for both objects and display the variables.  Demonstrate the use of the accessor method getColor() by accessing the color of each car and printing it to the console.  Use the method accel to increase the speed of the first car by 65 mph.  Use the method brake to set the speed of the first car to 0.  Add a third reference variable that refers to one of the existing objects.  Invoke the getColor() method for both reference variables that refer to the same object. They should both have the same color. Use println to print the color for both variables.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Modify the Car class example and add the following: 

  • A default constructor that initializes strings to “N/A” and numbers to zero.
  •  An overloaded constructor that takes in initial values to set your fields (6
  • parameters).
  • accel() method: a void method that takes a double variable as a parameter and

increases the speed of the car by that amount.

  • brake() method: a void method that sets the speed to zero.
  •  To test your class, you will need to instantiate at least two different Car objects in the main method in the CarDemo class.
  •  Each of your objects should use a different constructor. For the object that uses

the default constructor, you will need to invoke the mutator methods to assign

values to your fields.

  • Invoke the displayFeatures() method for both objects and display the variables.
  •  Demonstrate the use of the accessor method getColor() by accessing the color of each car and printing it to the console.
  •  Use the method accel to increase the speed of the first car by 65 mph.
  •  Use the method brake to set the speed of the first car to 0.
  •  Add a third reference variable that refers to one of the existing objects.
  •  Invoke the getColor() method for both reference variables that refer to the same

object. They should both have the same color. Use println to print the color for

both variables.



Options
********** Car 1 ******** ***
Make: Tesla
Model: Model X
Color: Red
Year: 2021
Price: $35999.0
Speed: 0.0 mph
*********** Car 2 ******
Make: Honda
Model: Civic
Color: Black
Year: 2018
Price: $17999.0
Speed: 0.0 mph
*********Invoking getColor() method**********
The color of the first car is Red and the color of the second color i
*********Invoking methods in Car Class***********
The first car is going with speed of 65.0 mph
After hitting the brake the speed of the first car is 0.0 mph.
*********Reference Variables*******
The color of the second car is Black
The color of the third car is Black
Transcribed Image Text:Options ********** Car 1 ******** *** Make: Tesla Model: Model X Color: Red Year: 2021 Price: $35999.0 Speed: 0.0 mph *********** Car 2 ****** Make: Honda Model: Civic Color: Black Year: 2018 Price: $17999.0 Speed: 0.0 mph *********Invoking getColor() method********** The color of the first car is Red and the color of the second color i *********Invoking methods in Car Class*********** The first car is going with speed of 65.0 mph After hitting the brake the speed of the first car is 0.0 mph. *********Reference Variables******* The color of the second car is Black The color of the third car is Black
Expert Solution
steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education