Question

In: Computer Science

Print three outputs corresponding to three tests that are based on different proposed bar sizes, such...

Print three outputs corresponding to three tests that are based on different proposed bar sizes, such as a small bar (25 seats), a medium sized bar (60 seats) and a big bar (100 seats).

CSMSoftwareGurusBar.java

public class CSMSoftwareGurusBar {
    private int freeChairs = 50;
    private double profit = 0.0;
    private SimulationFramework simulation = new SimulationFramework();
    private int[] beerType = {100, 60, 25};

    public static void main(String[] args) {
        CSMSoftwareGurusBar world = new CSMSoftwareGurusBar();
        System.out.println(world.beerType.length);
        CSMSoftwareGurusBar world2 = new CSMSoftwareGurusBar();
        System.out.println(world2);
        CSMSoftwareGurusBar world3 = new CSMSoftwareGurusBar();
    }

    CSMSoftwareGurusBar() {
        int t = 0;
        while (t < 240) { // simulate 4 hours of bar operation
            t += randBetween(2, 5); // new group every 2-5 minutes
            if (t <= 240)
                simulation.scheduleEvent(new ArriveEvent(t, randBetween(1, 5)));
        } // group size ranges from 1 to 5
        simulation.run();
        System.out.println("Total profits " + profit);
    }

    private int randBetween(int low, int high) {
        return low + (int) ((high - low + 1) * Math.random());
    }

    public boolean canSeat(int numberOfPeople) {
        System.out.println("Group of " + numberOfPeople
                + " customers arrives at time " + simulation.time());
        if (numberOfPeople < freeChairs) {
            System.out.println("Group is seated");
            freeChairs -= numberOfPeople;
            return true;
        } else
            System.out.println("No Room, Group Leaves");
        return false;
    }

    private void order(int beerType) {
        System.out.println("Serviced order for beer type " + beerType
                + " at time " + simulation.time());
        // update profit knowing beerType (left for you)
        profit += beerType + 1;
    }

    private void leave(int numberOfPeople) {
        System.out.println("Group of size " + numberOfPeople
                + " leaves at time " + simulation.time());
        freeChairs += numberOfPeople;
    }

    private class ArriveEvent extends Event {
        private int groupSize;

        ArriveEvent(int time, int gs){
            super(time);
            groupSize = gs;
        }

        public void processEvent(){
            if (canSeat(groupSize)){
                // place an order within 2 & 10 minutes
                simulation.scheduleEvent (new OrderEvent(time + randBetween(2,10), groupSize));
            }
        }
    }

    private class OrderEvent extends Event {
        private int groupSize;

        OrderEvent(int time, int gs) {
            super(time);
            groupSize = gs;
        }

        public void processEvent() {
            // each member of the group orders a beer (type 1,2,3)
            for (int i = 0; i < groupSize; i++) {
                order(1 + simulation.weightedProbability(beerType));
                order(2 + simulation.weightedProbability(beerType));
                order(3 + simulation.weightedProbability(beerType));
                // schedule a leaveEvent for this group
                // all the group leaves together (left for you)
                simulation.scheduleEvent(new LeaveEvent(time + randBetween(30, 60), groupSize));
            }
        }
    }

    private class LeaveEvent extends Event {
        LeaveEvent(int time, int gs) {
            super(time);
            groupSize = gs;
        }

        private int groupSize;

        public void processEvent() {
            leave(groupSize);
        }
    }
}

SimulationFrameWork.java

public class SimulationFramework {
    public void scheduleEvent(Event newEvent) {
        // put or addElement “newEvent” to the “eventQueue”
        // MinHeap Priority Queue (left for you)
        eventQueue.addElement(newEvent);
    }

    public void run () {
        while (! eventQueue.isEmpty()) {
            Event nextEvent = (Event) eventQueue.removeMin();
            currentTime = nextEvent.time;
            nextEvent.processEvent();
        }
    }

    public int time() {
        return currentTime;
    }

    private int currentTime = 0;
    private FindMin eventQueue = new Heap(new DefaultComparator());

    public int weightedProbability(int[] beerType){
        int sumOfArray = 0;
        for (int i=0; i < beerType.length; i++){
            sumOfArray += beerType[i];
        }

        int probability = 1 + (int) ((sumOfArray) * Math.random());

        if (probability <= 15){
            return 0;
        }
        else if (probability <= 75){
            return 1;
        }
        else{
            return 2;
        }
    }

    private class FindMin {
        public Object removeMin() {
                return currentTime ;
        }

        public boolean isEmpty() {
            return true;
        }

        public void addElement(Event newEvent) {
                System.out.println(newEvent);
        }
    }

    private class Heap extends FindMin {
        public Heap(DefaultComparator defaultComparator) {
            super();
        }
    }
}

Event.java

public abstract class Event implements Comparable {
    public final int time;
    public Event (int t) {
        time = t;
    }

    abstract void processEvent ();

    public int compareTo (Object o) {
        Event right = (Event) o;
        if (time < right.time) {
            return -1;
        }
        if (time == right.time){
            return 0;
        }
        return 1;
    }

}

DefaultComparator.java

public class DefaultComparator implements java.util.Comparator {


    public int compare(java.lang.Object left, java.lang.Object right) {
        Event i = (Event) left;
        Event j = (Event) right;
        if (i.time > j.time){
            return 1;
        }
        else if (i.time < j.time){
            return -1;
        }
        else{
            return 0;
        }
    }

    public boolean equals(java.lang.Object obj){
        return    this.equals(obj);

    }
}

Solutions

Expert Solution

The point where you might be getting it wrong may be you're saving the file with name with SimulationFrameWork.java, rather you should save it with the name SimulationFramework.java. and then the program will run smoothly. In a folder save these files as shown:

Just pass different inputs in line 5th of CSMSoftwareGurusBar.java

1.

private int[] beerType = {100, 60, 25};

OUTPUT:

2.

private int[] beerType = {10,8,5};

OUTPUT:

3.

private int[] beerType = {100, 60, 25};

OUTPUT:


Related Solutions

Mickey Company manufactures three different sizes of stuffed teddy bears (large, small and medium d corresponding...
Mickey Company manufactures three different sizes of stuffed teddy bears (large, small and medium d corresponding costs for the month of January 2004 are given below: large medium small projected unit sales 3,000 5,000 4,000 $ $ $ price per unit 40 30 20 variable cost per unit --direct material 12 10 8 --direct labour 8 5 3 --support costs 5 3 2 fixed cost per unit 2 2 2 total unit cost 27 20 15 It takes 20, 15...
A shipping company handles containers in three different sizes.
A shipping company handles containers in three different sizes. 1. 27 ft3 (3 x 3 x 3) 2. 125 ft33. 512 ft3 Let Xi (i = 1, 2, 3) denote the number of type i containers shipped during a given week. With μi = E(X;) and σi2 = V(Xi), suppose that the mean values and standard deviations are as follows. μ1 = 500 μ2 = 450 μ3 = 50σ1 = 8    σ2 = 12    σ3 = 10  Suppose that the Xi's are independent with...
Each of the following three datasets represent IQ Scores for three random samples of different sizes....
Each of the following three datasets represent IQ Scores for three random samples of different sizes. The population mean is 100 population standard deviation is 15. Compute the sample mean, median and standard deviation for each sample size: Sample Size 30 106 92 98 103 100 102 98 124 83 70 108 121 102 87 121 107 97 114 140 93 130 72 81 90 103 97 89 98 88 103
Each of the following three datasets represent IQ Scores for three random samples of different sizes....
Each of the following three datasets represent IQ Scores for three random samples of different sizes. The population mean is 100 population standard deviation is 15. Compute the sample mean, median and standard deviation for each sample size: 10) Using the sample size of 30 above in problem eight, your child was tested and has an IQ Score of 140. Calculate Z-Scores to answer these questions: a. If your child has an IQ Score of 75, what percentage of the...
There are three different types of tests we learned. What one of the three types is...
There are three different types of tests we learned. What one of the three types is the following? “ A researcher estimates that high school girls miss more days of school than high school boys. A sample of 16 girls showed that they missed an average of 3.9 days of school and a sample of 22 boys showed that they missed an average of 3.6 days. The standard deviation of the 16 girls was .6 and the standard deviation of...
Below are means, standard deviations, and sample sizes of three different data sets. Estimate the 90%...
Below are means, standard deviations, and sample sizes of three different data sets. Estimate the 90% confidence interval for dataset A, 95% for data set B, and 99% for set C. Set A: mean=6300, standard deviation= 300, n=200 Set B: mean=65, standard deviation= 15, n=75 Set C: mean=93, standard deviation= 37, n=200
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the...
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the number of units assembled correctly with each method, 30 employees were randomly selected and randomly assigned to the three proposed methods in such a way that each method was used by 10 workers. The number of units assembled correctly was recorded, and the analysis of variance procedure was applied to the resulting data set. The following results were obtained: SST=10,740; SSTR=4,540 a. Set up...
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the...
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the number of units assembled correctly with each method, 30 employees were randomly selected and randomly assigned to the three proposed methods in such a way that each method was used by 10 workers. The number of units assembled correctly was recorded, and the analysis of variance procedure was applied to the resulting data set. The following results were obtained: SST is 10, 760 SSTR...
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the...
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the number of units assembled correctly with each method, 30 employees were randomly selected and randomly assigned to the three proposed methods in such a way that each method was used by 10 workers. The number of units assembled correctly was recorded, and the analysis of variance procedure was applied to the resulting data set. The following results were obtained: SST is 10, 760 SSTR...
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the...
Three different methods for assembling a product were proposed by an industrial engineer. To investigate the number of units assembled correctly with each method, 30 employees were randomly selected and randomly assigned to the three proposed methods in such a way that each method was used by 10 workers. The number of units assembled correctly was recorded, and the analysis of variance procedure was applied to the resulting data set. The following results were obtained: SST = 10,780; SSTR =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT