Question: Need help writing a program in Java! 2. Design a Car class that has the following data fields: (1) define all data members as private;
Need help writing a program in Java!
2. Design a Car class that has the following data fields:
(1) define all data members as private; (1) add setter methods
color (String) year (int) maker (String) speed (double)
Define the following methods in the class: 2 constructors: the first constructor will initialize all data variables to default values (select you own default values for each data variables); the second constructor will use input arguments to initialize its data variables;
Methods to get individual data fields;
Methods to change speed of a car object: o speedUp() to increase the speed by 10 miles per hour until it reaches the maximum speed which is 160; o slowDown () to decrease the speed by 10 miles per hour until it reaches 0;
Write a Demo/Test program to demonstrate how the class works: get input from console which include maker, color, year, and speed; create a car object using input arguments; display all internal information in a car; call the speedUp() method five times and the slowDown() method four times, display cars final speed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
