Question: Overall specification: To write a simple Java class Car that models a car. Details The information stored about each car will include its make e

Overall specification: To write a simple Java class Car that models a car.
Details
The information stored about each car will include its
make e.g. "Ford"; call this variable make
model e.g. "Mondeo"; call this variable model
miles per gallon; call this variable milesPerGallon
o you may assume that this is a whole number.
initial purchase price i.e. the price when sold for the first time; call this variable initialPurchasePrice
o you may assume that this is a whole number;
purchase price i.e. the price when bought by the present owner; call this variable purchasePrice
o you may assume that this is a whole number;
name of owner; call this variable nameOfOwner
o you may assume that this is a single line of text.
number of owners; call this variable numberOfOwners
whether the car has a catalytic converter or not; call this variable hasConverter.
Your class will need to have fields corresponding to these attributes.
Start by opening BlueJ, creating a new project called myCar which has a class called Car and set up the fields that
you need. Make sure that the class compiles before continuing.
Next, you will need to write a constructor for the class. Assume that each car is "built" by creating an object and
specifying its make, model, miles per gallon, initial purchase price and whether it has a catalytic converter.
Therefore, you will need a constructor that allows you to pass arguments to initialise these five attributes in the order
mentioned. Other fields should be set to an appropriate value. Again check that the class compiles before
continuing. If there are errors then you will know that they are caused by the code you have just typed in. Never
type in more than a single method without compiling -- otherwise if there are errors then it might be difficult to
know which lines of code have caused the problem.
When the car is sold to the first owner, you will need to set the purchase price and the new owner's name so you will
need mutator methods
setPurchasePrice()-- to set the purchase price;
setOwner()-- to set the name of the owner.
These methods will also be used when the car is sold on to a subsequent owner.
You should also write the mutator method
goingCleaner()-- this method simulates having the car fitted with a catalytic converter so that pollutant
gases are converted into less harmful ones.
-1- Tuesday, 08 October 2024
Programming 12024/2025
To obtain information about a Car object, you should write
accessor methods corresponding to two of the fields:
o getMake()-- which returns the make of the car;
o getModel()-- which returns the model;
o getPurchasePrice()-- which returns the purchase price.
Ideally we should have an accessor method for every attribute that is of interest to us, but three accessor
methods is sufficient for this homework J.
an accessor method printDetails() to print, to the terminal window, a report about the car e.g.
This vehicle is a Ford Mondeo. It has had 2 owners and its present owner is
Mrs Brown. It does 35 miles per gallon and does not have a catalytic
converter. The original purchase price was 4500 and the price is now 3500.
Check that the new method works correctly by, for example,
o creating a Car object and setting its fields;
o calling printDetails() and checking that the report corresponds to the details you have just
given for the car;
o selling the car by calling setOwner() and setPurchasePrice();
o calling printDetails() and checking that the report now prints out the new details..
write a method sell() which simulates selling the car.
write an accessor method checkCarConverter() which checks whether the car has a catalytic converter
or not. If the car does not have a converter then this method returns a string containing the message Be
aware that your car could be less polluting, otherwise it returns a string containing This
car is better for the environment.
o Also try to output this message when the constructor is executed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Programming Questions!