Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

files needed car.java //(c) A+ Computer Science //www.apluscompsci.com //Name - //design your Car class //write all code for your Car class here //test your Car

image text in transcribed

files needed

car.java

//(c) A+ Computer Science //www.apluscompsci.com //Name -

//design your Car class //write all code for your Car class here //test your Car class with the CarRunner

CarRunner.java

//(c) A+ Computer Science //www.apluscompsci.com //Name -

public class CarRunner { public static void main( String[] args ) { Car c = new Car( 9000, 3000 ); //single constructor that takes in miles //driven and when to change the oil //assumes car has never had an oil change //sets last oil change mileage to 0 System.out.println( c.timeForOilChange( ) ); //checks if it is time to change oil //returns true as 9000 is >= 3000 //resets last oil change mileage to 0 c.addMiles( 2000 ); //add 2000 miles to miles driven System.out.println( c.timeForOilChange( ) ); //checks if it is time to change oil //car has driven 2000 miles since //last oil change returns false c.addMiles( 2000 ); //add 2000 miles to miles driven System.out.println( c.timeForOilChange( ) ); //checks if it is time to change oil //car has now driven 4000 miles since //last oil change return true //4000 is >= 3000 so time to change oil } }

A+ Computer Science CAR 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 Sample Runner Code: Car c = new Car ( 9000, 3000); //single constructor that takes in miles //driven and when to change the oil //assumes car has never had an oil change //sets last oil change mileage to o System.out.println( c.timeForOilChange()); //checks if it is time to change oil //returns true as 9000 is >= 3000 //resets last oil change mileage to o c.addMiles ( 2000); //add 2000 miles to miles driven System.out.println( c.timeForOil Change()); // checks if it is time to change oil // car has driven 2000 miles since //last oil change - returns false c.addMiles ( 2000 ); System.out.println( c.timeForOil Change()); //add 2000 miles to miles driven //checks if it is time to change oil //car has now driven 4000 miles since //last oil change - return true 1/4000 is >= 3000 so time to change oil Sample Output: true false Files Needed:: Car.java CarRunner.java true

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions