Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA HELP! . . Write a Java console application that processes customers through their store checkout line. The application has the following two classes: .

JAVA HELP!

.

.

Write a Java console application that processes customers through their store checkout line. The application has the following two classes:

.

Customer.java

This class represents one customer and includes:

Fields:

static totalCustomers initialize to 0 in declaration.

static totalItems initialize to 0 in declaration.

static totalCost initialize to 0 in declaration.

ID unique number assigned to each customer.

items number of items in customer shopping cart.

cost cost of all items in customer shopping cart.

next pointer to next customer.

A constructor with no parameters that sets the fields, respectively, to these values:

totalCustomers = totalCustomers + 1

ID = -1

items = -1

cost = -1

next = null

A constructor with two parameters that sets the fields, respectively, to these values:

totalCustomers = totalCustomers + 1

totalItems totalItems + items

totalCost = totalCost + cost

ID set to totalCustomers

items set from parameter

cost set from parameter

next = null

Getter methods for each field (declare the getters for totalCustomers, totalItems, and totalCost static).

Setter methods for each field (declare the setters for totalCustomers, totalItems, and totalCost static).

equals method that compares items and cost for equality.

toString method for returning instance variable values only.

.

HW7.java

This class contains the main method and uses the other class to represent customers in the store checkout line. Begin with an empty queue. Create the following three methods:

void insertCustomerOrder(Customer ptr) this method adds a customer to the queue. Insure that the three static fields (totalCustomers, totalItems, and totalCost) are properly updated.

Customer removeCustomerOrder() this method removes a customer from the queue. Do not modify the three static fields (totalCustomers, totalItems, and totalCost). These are used to track all checkout operations.

void printCustomers() this method prints the customers in the queue. It prints the ID, items, and cost for each customer formatted in three columns.

.

In the main method, loop twenty times. Within each loop, either add a customer to the queue or remove a customer from the queue, and then print the customers in the queue. Add a customer if the queue is empty or if a randomly generated value is true (use random function nextBoolean for this). Otherwise, remove a customer. Print a message showing the ID of the customer added or removed. When adding a customer:

Generate a random number between 1 and 40 for their number of items.

Generate a random number between 1 and 200 for their cost.

.

Keep track of the number of customers that entered the queue, and the number of customers handled (left the queue). At the bottom of each loop, pause execution for one second with Thread.sleep(1000); After the loop, print the number of customers handled and still in the queue.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

Students also viewed these Databases questions

Question

Does it avoid typos and grammatical errors?

Answered: 1 week ago

Question

4. Help trainees set challenging mastery or learning goals.

Answered: 1 week ago

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago