Implement a class Car as described below. A Car shall have a brand, model and mileage. The class Car should have a proper constructor to set the brand and model of a car. A new car should have mileage as 0 km. The class Car provides public method getBrand and getModel to access the car’s brand and model respectively. The class Car provides a public method drive to increment the mileage by 1 km. (10 marks)
class Car {
private String brand;
private String model;
private int mileage;
Car(String brand, String model) {
this.brand=brand;
this.model=model;
this.mileage=0;
}
public String getBrand() { return brand; }
public String getModel() { return model; }
public void incMileAge() { mielage = mileage + 1; }
}
Comments
Leave a comment