1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
LUCKY_DIMON [66]
3 years ago
10

A small grocery store has one checkout.You have been asked to write a program to simulate the grocery store as it checks out cus

tomers.YOU ARE REQURED TO USE A QUEUE TO SOLVE THE PROBLEM.The queue program (qu.py) is located on the Instructor drive.Here are some guidelines:
1. A customer gets to the checkout every 1 – 5 minutes
2. The checker can process one customer every 5 – 15 minutes (depends on how many groceries customer has 10 items or less will take 5 minutes, 11- 20 items will take 6 10 minutes, more than 20 items will take 11-15 minutes- you will need two random numbers)
3. The program should find the average wait time for customers and the number of customers left
4. Use the random number generator to get values for when customers get to the checkout and 5 You are not required to use classes, but it might make things easier than 20 items will take 11 - 15 minutes-you will need two random numbers) in the queue how long the checker will take.
Computers and Technology
1 answer:
Masteriza [31]3 years ago
5 0

Answer:

Check the explanation

Explanation:

PYTHON CODE :

#import random function

from random import randint

#class Queue declaration

class Queue:

#declare methods in the Queue

def __init__(self):

self. items = []

def isEmpty(self):

return self. items == []

def enqueue(self, item):

self.items. insert(0, item)

def dequeue(self):

return self. items. pop()

def size(self):

return len(self. items)

def getInnerList(self):

return self.items

#This is customer Queue

class Customer:

#declare methods

def __init__(self,n):

self.numberOfItems=n

def __str__(self):

return str(self. numberOfItems)

def getNumberOfItems(self):

return self. numberOfItems

#This is expresscheker customer queue

class Expresschecker:

def __init__(self,n):

self.numberOfItems=n

def __str__(self):

return str(self. numberOfItems)

def getNumberOfItems(self):

return self. numberOfItems

#Returns random checkout time, based on number of items

def checkOut(Expresschecker):

items = Expresschecker. getNumberOfItems()

if items <= 10:

return randint(2, 5)

if items <= 20:

return randint(6, 9)

return randint(10, 14)

#Initiate queue for the Expresschecker

Expresschecker = Queue()

#declare total customers

totalcheckoutCustomers = 10

#express Customers shopping..

for i in range(totalcheckoutCustomers):

#Each putting Between 1 to 25 items

randomItemsQty = randint(1, 25)

customer = Customer(randomItemsQty)

#Getting into queue for checkout

Expresschecker. enqueue(customer)

#====Now all express Customers having

#random qty of items are in Queue======

#intial time

totalTime=0

#define the size of the queue

totalcheckoutCustomers = Expresschecker. size()

#using for-loop until queue is empty check out

#the items in the express cheker queue

while not(Expresschecker. isEmpty()):

totalTime+=randint(1,5)

#Picking a customer

expresscustomer = Expresschecker. dequeue()

#Processing the customer

timeTaken = checkOut(expresscustomer)

#add the time for each custimer

totalTime+=timeTaken

#compute average waiting time

averageWaitingTime = totalTime/totalcheckoutCustomers

#display the average waiting time

print("Average waiting time for the express customer queue is "

+str(averageWaitingTime)+" minutes ")

print("Remaining Custimers in the express customer Queue is: ",

Expresschecker. size())

#Returns random checkout time, based on number of items

def checkOut(customer):

items = customer. getNumberOfItems()

if items <= 10:

return randint(1, 5)

if items <= 20:

return randint(6, 10)

return randint(11, 15)

#in

customersQueue = Queue()

totalCustomers = 20 #Change number of customers here

#Customers shopping..

for i in range(totalCustomers):

#Each putting Between 1 to 25 items

randomItemsQty = randint(1, 25)

customer = Customer(randomItemsQty)

#Getting into queue for checkout

customersQueue. enqueue(customer)

#====Now all Customers having random qty

#of items are in Queue======

totalTime=0

totalCustomers = customersQueue. size()

while not(customersQueue. isEmpty()):

totalTime+=randint(1,5)

#Picking a customer

customer = customersQueue. dequeue()

#Processing the customer

timeTaken = checkOut(customer)

totalTime+=timeTaken

#Result=============================

averageWaitTime = totalTime/totalCustomers

print("Average wait time for the customer queue is

"+str(averageWaitTime)+" minutes ")

print("Remaining Customers in the customer Queue is:

",customersQueue. size())

You might be interested in
Why does Brainly not have a astronomy section. (I'd prefer brainly answer this)
elena55 [62]
Could you by any chance help me with my business work?! Please go to my profile and go to the questions that have the subject business!
6 0
3 years ago
Iven the code fragment below with nested if statements, rewrite the code to combine all the tests into one if statement with mul
Georgia [21]

Answer:

See Explanation Below

Explanation:

The new code segment is

int feb = 28;

if ((year % 4) == 0 && (year % 100) != 0) // assume that year is an integer with a valid year value

{

System.out.println("This is a leap year");

feb = 29;

}

Assume year = 2020, the assigned value of feb is 29;

Reason below;

At line 2 of the new code segment, two conditions are tested both of which must be satisfied.

1. year % 4 == 0

2020 % 4 = 0

0 = 0 (True)

2. year % 100 != 0

2020 % 100 != 0

20 != 0 (True)

Since both conditions are true, the value assigned to feb will be 29 and

"This is a leap year" will be printed without the quotes

8 0
3 years ago
Read 2 more answers
Which new development in malware caused sandbox technology to automate and introduce artificial intelligence learning
Karo-lina-s [1.5K]

AI-driven attacks caused sandbox technology to automate and introduce artificial intelligence learning. AI and machine learning can be used to fight against malware attacks.

<h3>Artificial intelligence, machine learning, and malware</h3>

Artificial intelligence (AI) refers to the ability of a PC to perform tasks done by humans due to the requirement of discernment.

Machine learning is a subdivision of (AI) based on the use of data and algorithms to mimic human learning.

Malware is malicious software generated by cybercriminals, which are capable of stealing unauthorized information.

Learn more about malware here:

brainly.com/question/399317

4 0
2 years ago
Alcohol damages your __________, making it more difficult to understand how far away other objects are.
Zolol [24]

The answer to the blank part of the statement is vision.

When you consume alcohol, your pupils would react slower; you would be less likely to contrast dark and light objects well; your eyes would twitch if your consumption is excessive; and you have dry eye, your symptoms would be exacerbated. This is one of the reasons why people who are drunk aren’t allowed to drive, since they cannot accurately perceive the things around them due to being impaired by alcohol.

7 0
3 years ago
Create an application for a library and name it FineForOverdueBooks. TheMain() method asks the user to input the number of books
andrew11 [14]

Answer:

//The Scanner class is imported which allow the program to receive user input

import java.util.Scanner;

//Class Solution is defined to hold problem solution

public class Solution {

   // The main method which signify the begining of program execution

   public static void main(String args[]) {

       // Scanner object 'scan' is defined to receive input from user keyboard

       Scanner scan = new Scanner(System.in);

       // A prompt is display asking the user to enter number of books

       System.out.println("Please enter number of books: ");

       // the user response is assigned to numberOfBook

       int numberOfBook = scan.nextInt();

       // A prompt is displayed asking the user to enter the number of days over due

       System.out.println("Please enter number of days over due: ");

       // the user response is assigned to numberOfDaysOverDue

       int numberOfDaysOverDue = scan.nextInt();

       //displayFine method is called with numberOfBook and numberOfDaysOverDue as arguments

       displayFine(numberOfBook, numberOfDaysOverDue);

   

   }

   

   //displayFine method is declared having two parameters

   public static void displayFine(int bookNumber, int daysOverDue){

       // fine for first seven days is 10cent which is converted to $0.10

       double firstSevenDay = 0.10;

       // fine for more than seven days is 20cent which is converted to $0.20

       double moreThanSevenDay = 0.20;

       // the fine to be paid is declared

       double fine = 0;

       // fine is calculated in the following block

       if(daysOverDue <= 7){

           //the fine if the over due days is less than or equal 7

           fine = bookNumber * daysOverDue * firstSevenDay;

       } else{

           // the extra days on top of the first seven days is calculated and assigned to extraDays

           int extraDays = daysOverDue - 7;

           //fine for first seven days is calculated

           double fineFirstSevenDays = bookNumber * 7 * firstSevenDay;

           // fine for the extradays is calculated

           double fineMoreThanSevenDays = bookNumber * extraDays * moreThanSevenDay;

           // the total fine is calculated by adding fine for first seven days and the extra days

           fine = fineFirstSevenDays + fineMoreThanSevenDays;

       }

       // The total fine is displayed to the user in a nice format.

       System.out.printf("The fine for " + bookNumber + " book(s) for " + daysOverDue + " day(s) is: $%.02f", fine);

   }

}

Explanation:

The program first import Scanner class to allow the program receive user input. Then the class Solution was defined and the main method was declared. In the main method, user is asked for number of books and days over due which are assigned to numberOfBook and numberOfDaysOverDue. The two variable are passed as arguments to the displayFine method.

Next, the displayFine method was defined and the fine for the first seven days is calculated first if the due days is less than or equal seven. Else, the fine is calculated for the first seven days and then the extra days.

The fine is finally displayed to the user.

4 0
3 years ago
Other questions:
  • What are examples of educational obstacles to a career plan?
    13·1 answer
  • *Please* read before answering.
    14·1 answer
  • The part of the poppet valve that contacts the valve seat is called the?
    10·2 answers
  • What is a slide master ?
    8·2 answers
  • Which is a form of cyber bullying??
    9·1 answer
  • Suppose testcircle1 and circle1 in listing 9.1 are in two separate files named testcircle1.java and circle1.java, respectively.
    14·1 answer
  • Look at the network topology. What will happen with the other computers if the computer breaks at the RED X?
    8·1 answer
  • Sypherpk is good go sub 2 him
    6·2 answers
  • How do you do 1.17.5, invert colors, on codehs?
    10·1 answer
  • Which type of measurement would you use to determine the mass of sugar?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!