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

This program will simulate a car wash. The data structure used is a queue implem

ID: 3627714 • Letter: T

Question

This program will simulate a car wash. The data structure used is a queue implemented as a linked list. Vehicles arrive at the car wash and wait in line. The probability that a vehicle will arrive at any given moment is 25%. The probability of that vehicle being a SUV is 35%. It takes 3 minutes to wash a car and 5 minutes to wash a SUV. It costs $12 to wash a car and $18 to wash a SUV. A car cannot enter the wash until the car ahead of it leaves. Run the simulation for 8 hours. There must be a class for the vehicles and a driver class. (no pun intended). The output of the program should be:

Cars Washed: ------ Car Revenue: $------
SUVs Washed: ------ SUV Revenue $------
Total Revenue: $-------
Vehicles left in queue at closing time ------

Explanation / Answer

import java.util.LinkedList; public class CarWash{ private LinkedList carsInLine = new LinkedList(); int clock = 0; //in minutes int carsWashed = 0; int SUVsWashed = 0; int carRevenue = 0; int SUVRevenue = 0; public void simulation(){ Vehicle newVehicle; Vehicle currentVehicle = null; boolean currentVehicleIsSUV = false; int minutesBeingWashed = 0; while(clock < 480){ //one clock cycle = one minute. You can change this if you want. if(Math.random() < .25){ //vehicle arrives if(Math.random() < .35){ //vehicle is an SUV newVehicle = new Vehicle(true); } else{ //vehicle is a car newVehicle = new Vehicle(false); } carsInLine.add(newVehicle); } minutesBeingWashed++; if(carsInLine.peekFirst() != null){ //cars in line if(currentVehicle == null){ currentVehicle = (Vehicle)carsInLine.removeFirst(); minutesBeingWashed = 1; currentVehicleIsSUV = currentVehicle.isVehicleSUV(); if(currentVehicleIsSUV){ SUVsWashed++; SUVRevenue += 18; } else{ carsWashed++; carRevenue += 12; } } else{ //vehicle currently being washed minutesBeingWashed++; if(currentVehicleIsSUV){ if(minutesBeingWashed >= 5){ //SUV finishes and moves out currentVehicle = null; } } else{ if(minutesBeingWashed >= 3){ currentVehicle = null; //car finishes and moves out } } } } clock++; } } public static void main(String[] args){ CarWash c = new CarWash(); c.simulation(); System.out.println("Cars Washed: " + c.carsWashed + " Car Revenue: $" + c.carRevenue); System.out.println("SUVs Washed: " + c.SUVsWashed + " SUV Revenue: $" + c.SUVRevenue); System.out.println("Total revenue: $" + (c.carRevenue + c.SUVRevenue)); System.out.println("Vehicles left in queue at closing time: " + c.carsInLine.size()); } } public class Vehicle{ private boolean isSUV; public Vehicle(boolean SUV){ isSUV = SUV; } public boolean isVehicleSUV(){ return isSUV; } }
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