Write a class named Car that has the following fields:
- yearModel. The yearModel field is an integer that holds thecar’s model year.
- make. The make field references a String object that holds themake of the car.
- speed. The speed field is an double that holds the car’scurrent speed.
In addition, the class should have the following constructor andother methods:
- Constructor. The constructor should accept the car’s year modeland make as arguments. These values should be assigned to theobject’s modelYear and make fields. The constructor should alsoassign 0 to the speed field.
- Accessors. Appropriate accessor methods should get the valuesstored in an object’s modelYear, make, and speed fields.
- Create a method called accelerate. The accelerate method shouldadd 8 to the speed each time it is called.
- Create a method called brake. The brake method should subtract6 from the speed each time it is called.
2. Create a class called CarView that inherits from JFrame andaggregates the following GUI elements:
- A label and text field showing the modelYear of a car
- A label and text field showing the make of a car
- A label and text field showing the speed of a car
- A button that accelerates the car and updates the speed fieldwith the new speed
- A button that brakes the car and updates the speed field withthe new speed
Give each GUI widget a meaningful name, such as modelYearLableand modelYearField.
Implement the GUI in a separate class called CarView which takes acar in it’s constructor. The CarView should be started in a staticmain with:
new CarView(new Car(…));
Implement the ActionListeners for the buttons either as separatepublic classes, private nested classes or as anonymous innerclasses
need the JAVA CODE
Expert Answer
Answer to Write a class named Car that has the following fields: yearModel. The yearModel field is an integer that holds the car�…