Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Goal : This lab was designed to teach you more designing and writing classes. Use the same runner code below and associated comments to

Lab Goal : This lab was designed to teach you more designing and writing classes. Use the same runner code below and associated comments to create a Car class. Lab Description : Write a Car class that will keep track of miles driven and when you need to change your oil.
this is my code, but I dont want to use "this." in my code
public class Car {
private int milesDriven;
private int oilChange;
private int lastOilChangeMileage;
public Car(int initialMiles, int oilChange){
this.milesDriven = initialMiles;
this.oilChange = oilChange;
this.lastOilChangeMileage =0;
}
public boolean timeForOilChange(){
if (milesDriven - lastOilChangeMileage >= oilChange){
lastOilChangeMileage = milesDriven;
return true;
} else {
return false;
}
}
public void addMiles(int additionalMiles){
milesDriven += additionalMiles;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions