Question

In: Computer Science

Suppose there is only one customer service available in SAMBA Bank in Thursday morning, in every...

Suppose there is only one customer service available in SAMBA Bank in Thursday morning, in every 4 minutes a new customer arrives at the end of waiting line, each customer will need 7 minutes for the service

Write a program to print out the information after the first 60 minutes

  • The time of arriving for each customer
  • The time of leaving for each customer
  • How many customers are in the line?
  • Who is the current serving customer?

(((( data structure course

Programming Language: java
Hint: use the queue concept )))

Solutions

Expert Solution

Summary:

In order to fulfill this requirement we are using inbuild queue in java by importing from

java.util.Queue library.

Queue works in the FIFO manner that is the customer who comes first will be the first to go out of the queue.

I have mentioned comments for you better understanding. Please go through each comments its very easy implementaion.

----------------------------------------------------------------------Customer.java-------------------------------------------------------------------

import java.util.LinkedList;
import java.util.Queue;

public class Customer {
    int custId;
    int arrivingTime;
    int leavingTime;

    public Customer(int custId, int arrivingTime, int leavingTime) {
        this.custId = custId;
        this.arrivingTime = arrivingTime;
        this.leavingTime = leavingTime;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "custId=" + custId +
                ", arrivingTime=" + arrivingTime +
                ", leavingTime=" + leavingTime +
                '}';
    }

    public static void main(String args[]) {
        Queue<Customer> q = new LinkedList<>();

        int custId = 0;

        //Assuming first customer arrives at 0.
        q.add(new Customer(custId, 0, 7));


        for (int i = 1; i < 60; i++) {
            //add new customer to queue in every 4 mins.
            if (i % 4 == 0) {
                custId++;
                q.add(new Customer(custId, i, (i + 7)));
            }

            //remove customer from the queue end at every 7 min. Note queue works FIFO. i.e first in first out.
            if (i % 7 == 0) {
                q.remove();
            }
        }


        // Printing all the customers in the queue
        System.out.println("Total " + q.size() + " Customers are waiting in queue.");
        System.out.println("***************************************************");
        for (Customer customer : q) {
            System.out.println(customer);
            System.out.println();
        }

        // The peek() method of Queue Interface returns the element at the front the container. It does not deletes the element in the container.
        System.out.println("Current serving customer: " + q.peek());

        System.out.println("***************************************************");
    }
}

Output:

I enjoyed creating this solution, hope you'll enjoy it too after understanding.


Related Solutions

Suppose there is only one bank in the economy, Happy Bank. The citizens in this economy...
Suppose there is only one bank in the economy, Happy Bank. The citizens in this economy have 20 million in money, and they have all deposited their money in Happy bank. a. happy bank decides on a policy of holding 100% reserves. draw a T-account for the bank. b. Now, happy bank is required to hold 5% of its existing 20 million as reserves, and to loan out the rest. Draw a T-account for the bank after this first round...
Customer service is not only important to we the customer, but it is important our company...
Customer service is not only important to we the customer, but it is important our company and our customers. We want our customers to return again and again to improve the lifetime value of that customer to our company, right? Compare reactive and proactive customer service. Define customer service failure, and provide an example for a grocery store. What are customer needs and wants, and why are these important to the topic of customer service?
A bakery opens every day from Monday to Saturday, but only in the morning on Wednesdays....
A bakery opens every day from Monday to Saturday, but only in the morning on Wednesdays. It is known that the number of bread rolls sold daily follows a Gaussian distribution with mean 130 and standard deviation 20 with the exception of Wednesdays for which the distribution of the number of bread rolls sold is still Gaussian but with mean 100 and standard deviation 30. (a) What is the probability that on a Wednesday the bakery will sell more than...
Suppose we live in an economy with just one bank. Mary is the first customer of...
Suppose we live in an economy with just one bank. Mary is the first customer of the bank and makes a deposit of $500. The required reserve ratio is 10%. (Show Work) (a) What is the excess reserve amount? With this amount of excess reserve, is the bank allowed to make any loans? (b) What is the maximum amount of loan that the bank can make if the borrower does not withdraw the money. (c) What is the maximum amount...
Suppose you and a rival are the only producers of oysters in a town. Each morning...
Suppose you and a rival are the only producers of oysters in a town. Each morning you harvest oysters to sell in the afternoon. You both have the choice to collect 10 or 20 dozen oysters. Each dozen has a marginal cost of $10 (so the cost of 10 dozen oysters is $100). If 20 dozen oysters in total are brought to the market, they will sell for $35 each. If 30 dozen oysters in total are brought to the...
One morning a customer comes into Pierre’s and orders a random assortment of 6 Danish. At...
One morning a customer comes into Pierre’s and orders a random assortment of 6 Danish. At the time she comes in, there are 30 Danish sitting out: 13 apple, 10 cheese, and 7 raspberry. Assume the Danish are not replaced after they are selected. What is the probability that the second, fourth, and fifth Danish selected for the customer’s random assortment will be apple, and the other three will not be apple? Probability: What kind of problem is this, where...
Is it possible for an organisation to provide excellent customer service without every employee having a...
Is it possible for an organisation to provide excellent customer service without every employee having a job they feel makes a real contribution? Explain your answer. (50–100 words)
Suppose that the service time at a store with only, one check-out counter is Exponentially distributed,...
Suppose that the service time at a store with only, one check-out counter is Exponentially distributed, with a mean time of 10 minutes. a) What is the probability that a customer who is first in line now will spend more than 15 minutes waiting in the check-out line? (Solve using Exponential distribution and then using Poisson.) b) A customer has already been waiting in the line for more than 10 minutes. What is the probability that this customer will still...
A national bank that is developing very rapidly will impose a new mechanism in customer service....
A national bank that is developing very rapidly will impose a new mechanism in customer service. For this reason, trials were conducted at several branch offices. If from the trial it turns out consumers are more satisfied then the new mechanism will be applied to all of its branch offices. 24 customers were chosen to be asked for their opinion on the new mechanism. Their answer is to compare to various elements of the new mechanism with existing ones. There...
1- Suppose you were tasked with developing the customer service qualities required for an external customer...
1- Suppose you were tasked with developing the customer service qualities required for an external customer service role. Provide 4 customer service characteristics or skills you would require if you were tasked with hiring for an external customer service role. 1A- Explain why you believe these 4 qualities are important/should be required?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT