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

1.Programming language - Java Ambulances are dispatched at a rate of one every 1

ID: 3699983 • Letter: 1

Question

1.Programming language - Java

Ambulances are dispatched at a rate of one every 15 ± lO minutes in a large metropolitan area. Fifteen percent of the calls are false alanns, which require 12 ± 2 minutes to complete. All other calls can be one of two kinds. The first kind are classified as serious. They constitute 15% of the non-false alarm calls and take 25 ± 5 minutes to complete. The remaining calls take 20 ± 10 minutes to complete. Assume that there are a very large number of available ambulances, and that any number can be on call at any time. Simulate the system until 500 calls are completed.

Explanation / Answer

As per your requirement the below one is solution please follow it step by step

Here is the required code for you. Defined a method to simulate n number of calls and display the stats. Working of the method is well explained.

// AmbulanceCalls.java

import java.util.Random;

public class AmbulanceCalls {

                public static void main(String[] args) {

                                //simulating 500 calls

                                simulate(500);

                }

                /**

                * method to simulate n number of ambulance calls

                * @param calls - number of calls

                */

                static void simulate(int calls) {

                                /**

                                * Initializing all required variables

                                */

                                Random random = new Random();

                                int totalMinutesForAllCalls = 0;

                                int totalMinutesToComplete = 0;

                                int falseAlarms = 0;

                                int seriousAlarms = 0;

                                int normalAlarms = 0;

                                int i = 1;

                                /**

                                * looping until specified number of calls are simulated

                                */

                                while (i <= calls) {

                                                /**

                                                * generating a random time for call arrival

                                                */

                                                int callTime = 5 + random.nextInt(20 + 1); /*

                                                                                                                                                                                                                                * generates a value

                                                                                                                                                                                                                                * between 5 and 25

                                                                                                                                                                                                                                * (15-10 & 15+10)

                                                                                                                                                                                                                                */

                                                totalMinutesForAllCalls += callTime;

                                                /**

                                                * Generating a probability to check if the call is a false alarm or

                                                * not

                                                */

                                                int n = random.nextInt(100);// generating a number between 0 and 99

                                                if (n < 15) {

                                                                /**

                                                                * false alarm

                                                                */

                                                                falseAlarms++;

                                                                int timeToComplete = 10 + random.nextInt(4 + 1);/*

                                                                                                                                                                                                                                                                * between 10

                                                                                                                                                                                                                                                                * and 14

                                                                                                                                                                                                                                                                */

                                                                totalMinutesToComplete += timeToComplete;

                                                } else {

                                                                /**

                                                                * Not false, now generating a probability to check if the call

                                                                * is serious or not

                                                                */

                                                                n = random.nextInt(100);

                                                                if (n < 15) {

                                                                                /**

                                                                                * Serious call

                                                                                */

                                                                                seriousAlarms++;

                                                                                /* generating a random time to complete between 20 and 30 */

                                                                                int timeToComplete = 20 + random.nextInt(10 + 1);

                                                                                totalMinutesToComplete += timeToComplete;

                                                                } else {

                                                                                /**

                                                                                * Not serious call

                                                                                */

                                                                                normalAlarms++;

                                                                                /* generating a random time to complete between 10 and 30 */

                                                                                int timeToComplete = 10 + random.nextInt(20 + 1);

                                                                                totalMinutesToComplete += timeToComplete;

                                                                }

                                                }

                                                i++; //next call

                                }

                                /**

                                * Displaying all the stats including the average

                                */

                                System.out.println(calls + " calls have been simulated");

                                System.out.println("Number of false alarms: " + falseAlarms);

                                System.out.println("Number of serious alarms: " + seriousAlarms);

                                System.out.println("Number of normal alarms: " + normalAlarms);

                                System.out.println("Total minutes taken for getting " + calls

                                                                + " calls: " + totalMinutesForAllCalls);

                                System.out.println("Average minutes per call arrival: "

                                                                + (double) totalMinutesForAllCalls / calls);

                                System.out

                                                                .println("Time taken to complete all tasks by all ambulances combined: "

                                                                                                + totalMinutesToComplete + " minutes");

                                System.out.println("Average time to complete one call: "

                                                                + (double) totalMinutesToComplete / calls);

                }

}

/*OUTPUT*/

500 calls have been simulated

Number of false alarms: 71

Number of serious alarms: 75

Number of normal alarms: 354

Total minutes taken for getting 500 calls: 7339

Average minutes per call arrival: 14.678

Time taken to complete all tasks by all ambulances combined: 9751 minutes

Average time to complete one call: 19.502