Answer to Question #276131 in Java | JSP | JSF for Candy

Question #276131

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)


1
Expert's answer
2021-12-11T01:57:57-0500
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; }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS