Question: SuperMarket - WRITE IN JAVA Summary of problem: This program models a supermarket. There are two types of shoppers fast shoppers and big shoppers. They
SuperMarket - WRITE IN JAVA
Summary of problem: This program models a supermarket. There are two types of shoppers fast shoppers and big shoppers. They are all mixed together when shopping, but go onto different lines when checking out. Checking out requires waiting online, and then actually being checked out, once the clerk is available. After either type of shoppers is checked out that shopper is put into a separate list of those who are done shopping.
interface ShoppingTimeRemaining (5 points)
Has two abstract methods
setShoppingTimeRemaining accepts an int value and a void return
getShoppingTimeRemaining has no parameters and returns an int
class Shopper (15 points) implements ShoppingTimeRemaining
This is an abstract class.
It has one instance variable shopperType of type String.
It has a default constructor that calls the setShopperType method with an empty String
It has a second constructor with a String parameter referring to the shopperType, that calls the setShopperType method with the parameters value
It has both mutator and accessor methods for shopperType.
It has four public abstract methods:
setTimeIntoCheckoutLine accepts an int value and a void return
getTotalTimeCheckingOut has no parameters and returns an int
class FastShopper is a subclass of Shopper (20 points) note: all the abstract methods in Shopper and in the interface ShoppingTimeRemaing are implemented here
Note: You dontr\ say implement in the class header since you this is done in Shopper
It has a public static int variable fastShopperCounter set to 0
It has a public static int variable TIMEWITHCHECKER = 1
It has a private String instance variable fastShopperID note: has a simple accessor method
It has the following additional private instance int variables, each of which has a simple accessor method that returns its current value. Those with an * also have a simple mutator method
- startTime*
- timeShopping
- shoppingTimeRemaining*
- timeIntoCheckoutLine*
- timeOutOfCheckoutLine
- endTime calculated in calculateFinalDurations method
- totalTimeCheckingOut - calculated in calculateFinalDurations method
- totalTimeInStore - calculated in calculateFinalDurations method
It also has a Random reference variable randy (dont forget the proper import statement)
There is one constructor with one int input for the startTime;.
- It calls the super constructor with the String FastShopper
- It creates a Random object that randy refers to using as the seed the fastShopperCounter
- It calls setFastShopperID() with no parameters
- It calls setStartTime with the startTime as the parameter
- It calls setTimeShopping with no parameters
- It calls setShoppingTimeRemaining with the timeShopping (Must be done last)
The following methods has special code used in the mutator method.
setFastShopperID has no parameters and a void return.
It increments fastShopperCounter by 1 sets fastShopperID equal to the concatenation of the return from getShopperType() and fastShopperCounter
setTimeShopping has no parameters and a void return
It sets the timeShopping variable to a value between 1 and 6 inclusively using the randy Random object
setTimeOutOfCheckoutLine has an int input parameter and a void return
It sets timeOutOfCheckoutLine to the input parameter value It calls calculateFinalDurations with no parameters
There are two additional methods.
calculateFinalDurations has no parameters and a void return and sets the following values:
endTime equals the sum of timeOutOfCheckoutLine and TIMEWITHCHECKER
totalTimeCheckingOut is the positive difference of the endTime and timeIntoCheckoutLine
totalTimeInStore is the positive difference between the endTime and the startTime;
There is also a toString method that returns a formatted String for printing as shown in the output. It includes the following values: fastShopperID, startTime, endTime, timeShopping, totalTimeCheckingOut, totalTimeInStore
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
