Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to display my results by inserting a main method within the car class I have included the code I have so far.

I am trying to display my results by inserting a main method within the car class I have included the code I have so far.

Programming in java

Car

For this assignment, you will design a set of classes that work together to simulate a car, including its fuel gauge and odometer.

MY CODE

//FuelGauge

public class FuelGauge { // instance variable private int fuel;

// know about current fuel public void setFuel(int fuel) { this.fuel = fuel; }

// report current fuel public int getFuel() { return fuel; }

// increae current fuel public void increaseFuel() { if (fuel <= 15) fuel++; }

// decrease current fuel public void decreaseFuel() { if (fuel > 0) fuel--; }

}

//Odometer

public class Odometer {

// instance variable private int mileage;

// to know current mileage public void setMileage(int mileage) { this.mileage = mileage; }

// to report about mileage public int getMileage() { return mileage; }

// increament current milegae public void increaseMileage() { if (mileage <= 999999) mileage++; else mileage = 0; }

// decrease fuel for miles travelled public void fuelUsed(FuelGauge fuel) { int amount = mileage / 24;

for (int i = 0; i < amount; i++) fuel.decreaseFuel(); }

}

//Car

public class Car { // instance variables private int engineSize, numOfTires; private FuelGauge fuel; private Odometer odometer;

/** to know and report about car's engine size and number of tires **/

public int getEngineSize() { return engineSize; }

public void setEngineSize(int engineSize) { this.engineSize = engineSize; }

public int getNumOfTires() { return numOfTires; }

public void setNumOfTires(int numOfTires) { this.numOfTires = numOfTires; }

}

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

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago