design a Java application with multiple classes to emulate the operations at a g
ID: 3656124 • Letter: D
Question
design a Java application with multiple classes to emulate the operations at a gas station which has 2 gas pumps. Use a random number generator to determine client arrival, gas pump assignment and amount of gas to purchase. If both gas pumps are busy, turn the client away, or, for a bonus, put the client in a waiting line for the next available gas pump. The client can choose from one of the three types of gasoline available: premium, plus and regular. Print a receipt after each purchase. The application must have at least the following classes: Office: monitors the operations of gas pumps and inventory of gasoline GasPump: communicates with the client Client: contains a car license tag, time needed for the purchase On the screen, show activities of the gas station at end of each time unit, including what the clerk sees in the office and what the client sees at the gas pump.[ NOTE: PLEASE MAKE THE 2 GAS PUMPS IN THE SAME CLASS GasPump] I would really appreciate it thank you!!Explanation / Answer
import java.util.Random; public class Office { public static void main (String [ ] args) { double regularTank = 1000; double plusTank = 1000; double primiumTank = 1000; GasPump pump1 = new GasPump ( ); GasPump2 pump2 = new GasPump2 ( ); Random gen = new Random (); double output1 = 0, output2 = 0, gastotal = 0, gastotal2 = 0; //asuumint gas tanks always have gas, will upgrade later do { int whatHappens = gen.nextInt (100); if (whatHappens == 5) { System.out.println ("gas station closed"); System.out.println ("The Total Revenue from Pump1 :" + output1); break; } else if ((whatHappens % 10) == 0) { if (pump1.pumpAvailable ()) { System.out.println( "Pump 1 is open"); pump1.customerArrival ();} else System.out.println ("customer arrives, but is turned away, gas pump is busy"); } else { if (pump1.pumpAvailable ()) System.out.println ("no customer; waiting........."); } if (!pump1.pumpAvailable()) { if (pump1.updateClock () == 0) pump1.saleComplete (); } output1 = output1 + pump1.saleComplete (); } while (true); do { int whatHappens = gen.nextInt (100); if (whatHappens == 5) { System.out.println ("gas station closed"); System.out.println ("The total revenue from Pump 2 is" + output2); break; } else if ((whatHappens % 10) == 0) { if (pump2.pumpAvailable2 ()) pump2.customerArrival2 (); else System.out.println ("a new customer arrives, but is turned away, gas pump is busy"); } else { if (pump2.pumpAvailable2 ()) System.out.println ("no customer; waiting........."); } if (!pump2.pumpAvailable2()) { if (pump2.updateClock2 () == 0) pump2.saleComplete2 (); } output2 = output2 + pump2.saleComplete2 (); } while (true); System.exit (0); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.