Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add new fuel types to the provided class. *Electricity at 2 cents a gallon *Bio

ID: 3634598 • Letter: A

Question

Add new fuel types to the provided class.

*Electricity at 2 cents a gallon
*Bio Fuel at 80 cents a gallon

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

public class GasPump
{
final private double REGULAR_PRICE = 3.15;
final private double PLUS_PRICE = 3.5;
final private double PREMIUM_PRICE = 4.5;

private double totalPayment;
private Customer who;

public GasPump ()
{
who = null;
totalPayment = 0;
}

public void customerArrival ()
{
who = new Customer ();
System.out.println ("welcome to jack's gas station....");

int gasType = who.getGasType ();
double gasPurchased = who.getGasPurchased ();
String carTag = who.getCarTag ();
switch (gasType)
{
case 1: totalPayment = REGULAR_PRICE * gasPurchased; break;
case 2: totalPayment = PLUS_PRICE * gasPurchased; break;
case 3: totalPayment = PREMIUM_PRICE * gasPurchased; break;

}

printReceipt (gasType,gasPurchased,totalPayment);
resetPump ( );


}

private void printReceipt (int gasType, double gasPurchased, double totalPayment)
{
System.out.println ("****Sale Receipt");
switch (gasType)
{
case 1: System.out.println ("regular gas"); break;
case 2: System.out.println ("plus gas"); break;
case 3: System.out.println ("premium gas"); break;
}

System.out.println ("gas amount: " + gasPurchased +
" total payment" + totalPayment + " thank you");


}

private void resetPump ( )
{
who = null;
totalPayment = 0;
}


}

Explanation / Answer

Hi,

Assuming the gasTypes for the two new fuels are 4 (electricity) and 5 (biofuel), here's the updated code:

NOTE: Before each of my changes, I've placed a comment line // ***

Hope this helps, be sure to ask any questions you have.

Thanks,

Joe

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote