Write a class that represents a car. Each car has a year and a current mileage r
ID: 3576699 • Letter: W
Question
Write a class that represents a car. Each car has a year and a current mileage readings. Include an appropriate constructor, a toString() method, and an updateMileage() method that increase the mileage. You only need to provide one constructor, and that constructor must have two parameters that are used to initialize both data files. The toString() method must return a String that contains the year and mileage in a readable fashion. The updateMileage() method should have one parameter which is the amount to increase the mileage by. You do not need to write a main() method to test the class, just the class itself. public class car {Explanation / Answer
Hey, here's the class Car:
public class Car {
int year;
float currentMileage;
public Car(int year, float currentMileage) {
this.year = year;
this.currentMileage = currentMileage;
}
public void uodateMileage(float milage){
this.currentMileage+=milage;
}
public String toString() {
return "Car [year=" + year + ", currentMileage=" + currentMileage + "]";
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.