Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started