QUESTION

IN JAVA PLEASE. In this project we are going to create a class Sedan. A sedan is a four wheeled automobile with 4 doors. Each sedan can have a different gas tank that has a fixed capacity, and it can contain certain number of gallons of fuel. We will assume that each sedan can get a different fixed constant miles per gallon, and there is an EPA standard miles per gallon for all sedans that gets updates every year. The sedan also has a mileage. Right out of the factory, the sedan has a full tank of gas and zero mileage.

CLASS Sedan:

  1. Create the following variables in the class, and determine the type, if static, if final
    1. number of wheels
    2. number of doors
    3. epa mpg – make this private
    4. tank capacity
    5. current fuel level – make this private
    6. mpg
    7. mileage – make this private
  2. Create a non default c’tor for sedan

public Sedan(double ptankCapacity, double mpg)

    1. full tank
    2. zero mileage
    3. print warning to if it does not meet the current EPA requirements
  1. Create a default c’tor for sedan that calls the non default c’tor with the folloing
    1. tank = 10
    2. mpg = EPA mpg
  2. Define a toString method that prints basic stats of the sedan in the example below

public String toString()

  1. Define a drive method

public double drive(double miles)

    1. Drive either the specified miles or what the fuel allows
    2. Deduct fuel according to miles driven
    3. Return actual miles driven
  1. Define a pump fuel method

public double pumpFuel(double gallons)

    1. Pump with the specified gallons of what the fueld tank allows
    2. Return actual fuel pumped
  1. Overload a pump fuel method

public double pumpFuel()

    1. Fill up tank
    2. Return actual fuel pumped
  1. setEPA

public static boolean setEPA(double newEPAmpg)

    1. Sets the new EPA mpg
    2. Return true if new EPA mpg is > 0; else do not set and return false
  1. getEPA
    1. get the current EPA mpg
  2. getMileage
    1. get the current mileage
    2. note we cannot set the mileage directly because this is illegal!
  3. getFuel
    1. get the current fuel
  4. equals
    1. determine if two sedans are equal – justify your answer

CLASS SedanTest:

  1. Create a single global variable static Scanner sc = new Scanner(System.in);
  2. Define an utility method to read a non-negative number from the Scanner sc

static double readNNegDouble(String s)

    1. Print the prompt s
    2. Read a double from Scanner sc
    3. Return if the double is > 0
    4. Print error if no good and loop
  1. Define a printMenu method
  2. Define a main method
    1. Set EPA mpg to 25
    2. Create scanner
    3. Create default sedan s1
    4. Print it
    5. Read in tank capacity and mpg for sedan 2 – using the utility method readNNegDouble
    6. Create and print sedan s2
    7. Do loop that operates on s2
      1. printMenu
      2. get input string
      3. create switch statement to handle
        1. drive
          1. print actual miles driven
        2. pump fuel
          1. print actual gallons pumped
        3. pump up
          1. print actual gallons pumped
        4. change epa
        5. sedan stats
        6. quit
    8. print program terminated

Sample Output:

Sedan 1

Sedan 1 created.

Sedan with 4 wheels and 4 doors,

with 10.0 gallon fuel tank and 10.0 gallons fuel,

with 0.0 mileage,

and with 25.0 mpg meeting the EPA mpg of 25.0.

Sedan 2

Enter tank capacity:

-1

ERROR - input a non-negative number

Enter tank capacity:

10

Enter MPG:

-5

ERROR - input a non-negative number

Enter MPG:

25

Sedan with 4 wheels and 4 doors,

with 10.0 gallon fuel tank and 10.0 gallons fuel,

with 0.0 mileage,

and with 25.0 mpg meeting the EPA mpg of 25.0.

Sedan 2 created.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

d

Enter miles:

100

100.0 actual miles driven.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

p

Enter gallons:

50

4.0 actual gallons pumped.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

d

Enter miles:

1000

250.0 actual miles driven.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

u

10.0 actual gallons pumped.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

d

Enter miles:

200

200.0 actual miles driven.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

s

Sedan with 4 wheels and 4 doors,

with 10.0 gallon fuel tank and 2.0 gallons fuel,

with 550.0 mileage,

and with 25.0 mpg meeting the EPA mpg of 25.0.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

e

Enter EPA mpg:

30

EPA mpg updated.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

s

Sedan with 4 wheels and 4 doors,

with 10.0 gallon fuel tank and 2.0 gallons fuel,

with 550.0 mileage,

and with 25.0 mpg not meeting the EPA mpg of 30.0.

-------------

Menu

-------------

(D)rive

(P)ump fuel

Pump (U)p

Change (E)PA

Sedan (S)tats

(Q)uit

-------------

q

Program Terminated.

Public Answer

NZ5JQE The First Answerer