Question: Part I: Write a Java class named Car.java to represent a Car type Create a new Java class named Car that has the following fields:

Part I:

Write a Java class named Car.java to represent a Car type

Create a new Java class named Car that has the following fields:

year - The year field is an int that holds a cars year model (e.g. 2010)

make - The make field is a String object that holds the make of the car (e.g. "Porsche")

speed - The speed field is an double that holds a cars current speed (e.g. 25.0)

In addition, the Car class should have the following methods.

Constructor - The constructor should accept the cars year, make, and beginning speed as arguments

These values should be used to initialize the Cars year, make, and speed fields

Getter Methods - Write three accessor (getter) methods to get the values stored in an object fields:

getYear(), getMake(), getSpeed()

accelerate - Write an accelerate method that has no arguments (parameters) passed to it and adds 1 to the speed field each time it is called For example: if the car was going 3 mph, accelerate would set the speed to 4 mph

Part II: Write driver (tester) class named CarTester.java that uses your Car class:

1. create a new Car object

2. call accelerate method twice

3. printout car speed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Below is the stepbystep process to create the Car class and a CarTester class in Java Part I Car Cla... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!