Question
Could you create a UML for the following code, Preferably in the software DIA or Microsoft Word whichever is easier. (It doesnt have to be
Could you create a UML for the following code, Preferably in the software DIA or Microsoft Word whichever is easier. (It doesnt have to be very specific).
Example of the two classes Odometer and FuelGuage. I need TestCarInstrument as an UML as well.
/** FuelGauge class */
public class FuelGauge
{
// Constant for the maximum number of gallons
static final int MAX_GALLONS = 15;
// Field for the amount of fuel, in gallons
private int gallons;
/**
No-arg constructor
*/
public FuelGauge()
{
gallons = 0;
}
/**
Constructor
@param g The initial number of gallons.
*/
public FuelGauge(int g)
{
// Set gallons to g, but no more than
// the maximum amount.
if (g
gallons = g;
else
gallons = MAX_GALLONS;
}
/**
getGallons method
@return The number of gallons of fuel.
*/
public int getGallons()
{
return gallons;
}
/**
The incrementGallons method increments
the value of gallons. If gallons exceeds
the maximum amount, a message is displayed
incicating the fuel is overflowing.
*/
public void incrementGallons()
{
if (gallons
gallons++;
else
System.out.println("FUEL OVERFLOWING!!!");
}
/**
The decrementGallons method decrements
the value of gallons. If gallons is at 0
then a message is displayed indicating we
are out of fuel.
*/
public void decrementGallons()
{
if (gallons > 0)
gallons--;
else
System.out.println("OUT OF FUEL!!!");
}
}
/**
Odometer class
*/
public class Odometer
{
// Constant for the maximum mileage
static final int MAX_MILEAGE = 999999;
// Constant for the miles-per-gallon
static final int MPG = 24;
// Field for the current mileage
private int mileage;
// Field for the mileage set-point to
// remember when the FuelGuage gallons
// were decremented.
private int setPoint;
// Field to reference a FuelGauge object
private FuelGauge fuelGauge;
/**
Constructor
@param m Initial mileage.
@param fg A reference to a FuelGauge object.
*/
public Odometer(int m, FuelGauge fg)
{
mileage = m;
setPoint = m;
fuelGauge = fg;
}
/**
getMileage method
@return The mileage.
*/
public int getMileage()
{
return mileage;
}
/**
The incrementMileage method increments
the mileage field. If mileage exceeds the
maximum amount, it rolls over to 0.
*/
public void incrementMileage()
{
// Increment the mileage, but rollover
// if we go past the maximum amount.
if (mileage
mileage++;
else
mileage = 0;
// See if we have burned a gallon of gas. This
// happens every MPG miles.
//
// If setPoint is greater than mileage, then
// the odometer has rolled over.
if (setPoint > mileage)
{
// Add MAX_MILEAGE + 1 to get the actual mileage.
int falseMileage = mileage + MAX_MILEAGE + 1;
if ( (falseMileage - setPoint) >= MPG )
{
fuelGauge.decrementGallons();
setPoint = mileage;
}
}
else
{
if ( (mileage - setPoint) >= MPG )
{
fuelGauge.decrementGallons();
setPoint = mileage;
}
}
}
}
/**
Car Instrument Simulator
*/
public class TestCarInstrument
{
public static void main(String[] args)
{
// Create a FuelGuage object.
FuelGauge fuel = new FuelGauge();
// Create an Odometer object to work with the FuelGauge object.
Odometer odometer = new Odometer(0, fuel);
// Fill the car up with gas.
for (int i = 0; i
fuel.incrementGallons();
// Drive the car until it runs out of gas.
while (fuel.getGallons() > 0)
{
// Drive a mile.
odometer.incrementMileage();
// Display the mileage.
System.out.println("Mileage: " + odometer.getMileage());
// Display the amount of fuel.
System.out.println("Fuel level: " + fuel.getGallons() + " gallons");
System.out.println("------------------------------");
}
}
}
Odometer + MAXMILEAGE : int = 999999 + MPG int 24 - mileage int - setPoint: int - fuelGauge FuelGauge Odometer(m: int, tg : FuelGauge) +getMileage): int + incrementMileage0: void FuelGauge + MAXGALLONS = 15 : int - gallons: int + FuelGauge) FuelGauge(g: int) +getGallons(): int + incrementGallons) void +decrementGallons(): voidStep 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