Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class named Car that has the following fields : yearModel . The yearModel field is an int that holds the cars year model.

Write a class named Car that has the following fields:

yearModel. The yearModel field is an int that holds the cars year model.

make. The make field references a String object that holds the make of the car.

speed. The speed field is an int that holds the cars current speed.

In addition, the class should have the following constructor and other methods:

Constructor. The constructor should accept the cars year model and make as arguments. These values should be assigned to the objects yearModel and make fields. The constructor should also assign 0 to the speed field.

Accessors. Appropriate accessor methods should get the values stored in an objects yearModel, make, and speed fields.

Create a method called accelerate. The accelerate method should add 7 to the speed each time it is called.

Create a method called brake. The brake method should subtract 5 from the speed each time it is called.

Create a GUI with the following elements:

A label and text field showing the yearModel

A label and text field showing the make

A label and text field showing the speed

A button that accelerates the car and displays the new speed

A button that brakes the car and displays the new speed

Implement the GUI in a separate class called CarView which takes a car in it's constructor. Given each GUI widget a meaningfull name, such as yearModelLabel and yearModelField. Also, implement the ActionListeners for the buttons either as a private nested class or as anonymous inner classes . Use setText to update the contents of the text fields.

Write it in two different files 1 for Car class, 2 CarView

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

Step: 3

blur-text-image

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

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

What is Ohm's law and also tell about Snell's law?

Answered: 1 week ago

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago