Question: I need help finishing off my Computer Science Lab for the week. I have begun and need help implementing the rest of my lab into

I need help finishing off my Computer Science Lab for the week. I have begun and need help implementing the rest of my lab into my lab. Below I have attached what I have done so far, and my Exception class. Also, I have attached what we are to do to my Car class.

What is to be done:

Provide a getRange method to return the maximum distance that the car could travel by multiplying the current fuel amount and the fuel economy. The class should have an addFuel methods that takes a double amount of gallons and adds it to the current amount of fuel in the tank. This method returns nothing. The class should have a drive method that takes a double amount representing the number of miles to drive, computes the amount of fuel needed to drive that distance and subtracts it from the current amount of fuel in the tank. This method returns nothing. If the distance to drive exceeds the current range of the car (i.e., if there is not enough fuel) then the amount of fuel should be set to zero and an OutOfFuelException thrown with the shortfall amount of fuel passed into the constructor as outlined above (this should be a positive value).

My Car class:

public class Car{ private int licensePlate; private double fuelEconomy; private double Over; public Car(int c){ licensePlate = c; fuelEconomy = 0; } public int getLicensePlate(){ return licensePlate; } public double getFuelEconomy(){ return fuelEconomy; } public double getFuelRemaining(){ return fuelEconomy; } }

OutOfFuelException class:

public class OutOfFuelException extends Exception { double Amount; OutOfFuelException(double amount){ Amount = amount; } public double getShortfall() { return Amount; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!