Question: Create a Vehicle class with attributes: make, model, year and color - which defaults to blank and/or 0 (depending on datatype) and Silver for color.
Create a Vehicle class with attributes: make, model, year and color - which defaults to blank and/or 0 (depending on datatype) and Silver for color.
Provide a default constructor() as well as one or more constructors() that have parameters to set the attributes (i.e. overloaded constructor methods).
Provide a toString() method that displays or outputs all the vehicle information.
Provide set() methods for each attribute
Provide get() methods for each attribute.
(examples of set() and get() methods are in Fig 8.5. We have not learned exception handling yet so not required, however we do need to validate input parameter. If invalid, output message that it is an invalid and set attribute to its default value.
Use enumeration for the Color, you choose your valid colors (i.e. SILVER, RED, BLUE, BLACK etc). Below is a simple example of how to use enumeration.
submit VehicleTest.java that instantiates and uses your user-defined Vehicle data-type.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
