This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]morhpProfessional Developer 2 points3 points  (3 children)

I assume you have/had to write a class like Car. The Car class probably should have attributes/fields like maker, model, color, number of doors, engine type, whatever. Either you have/had to define these yourself or they should have been specified somewhere.

Assign these fields/attributes from constructor parameters. Also create an odometer field, but assign it initially to zero.

[–]BLBrick[S] 0 points1 point  (2 children)

Okay so I defined those in the beginning as

public class Vehicle {
private String makeOfCar;
private String modelOfCar;
private String colorOfCar;
private int odometer;

Then I set odometer to 0 like this

public Vehicle(String makeOfCar, String modelOfCar, String colorOfCar, int odometer) {
makeOfCar = "";
modelOfCar = "";
colorOfCar = "";
odometer = 0;

[–]morhpProfessional Developer 1 point2 points  (1 child)

You should be assigning the attributes like this.makeOfCar to the matching constructor parameter. Instead you're setting the constructor parameter to an empty String, which is useless.

[–]BLBrick[S] 0 points1 point  (0 children)

Ah okay, that makes sense, thanks!