Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have been hired by Bullseye Buys to write a Java console application that pr

ID: 3817042 • Letter: Y

Question

You have been hired by Bullseye Buys to 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.

Customer removeCustomerOrder() – this method removes a customer from the queue.

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.

Explanation / Answer

HW7.java

import java.util.*;
import java.lang.Thread.*;
public class HW7{
Customer first,tail;
  
public HW7(){
first=null;
tail=null;
}
  
public void insertCustomerOrder(Customer customer){
if(first==null)
{
first=customer;
tail=customer;
}else{
tail.setNext(customer);
tail=customer;
}
  
}
public Customer removeCustomerOrder(){
Customer firstCustomer=first;
first=first.getNext();
return firstCustomer;
}
  
public void printCustomers(){
Customer temp=first;
while(temp!=null){
System.out.println(temp.toString());
temp=temp.getNext();
}
}
public boolean isEmpty(){
return first==null;
}
  
public static void main(String[] args){
HW7 queue=new HW7();
Random random = new Random();
int customersHandled=0,customersInQueue=0;
for(int i=0;i<20;i++){
if(random.nextBoolean()||queue.isEmpty()){
Customer customer=new Customer((random.nextInt(40)+1),(random.nextInt(200)+1));
queue.insertCustomerOrder(customer);
customersInQueue+=1;
System.out.println("customer with ID: "+customer.getID()+" added to queue");
}else{
Customer customer=queue.removeCustomerOrder();
customersHandled+=1;

System.out.println("customer with ID: "+customer.getID()+" removed from queue");
}
try{
Thread.sleep(1000);
}catch(InterruptedException ie){
  
}
}

System.out.println(" ");
System.out.println("Total customer handled: "+customersHandled);
System.out.println("Total customers entered queue: "+customersInQueue);
if(!queue.isEmpty()){
System.out.println(" Displaying Customers still in queue:");
System.out.println("ID"+" "+"Items"+" "+"Cost");
queue.printCustomers();
}

}
  
}

Customer.java

public class Customer{
public static int totalCustomers=0;
public static int totalItems=0;
public static int totalCost=0;
private int ID;
private int items;
private int cost;
private Customer next;
public Customer(){
totalCustomers = totalCustomers + 1;
ID = -1;
items = -1;
cost = -1;
next = null;
}
public Customer(int itms, int cst){
totalCustomers+=1;
totalItems+=itms;
totalCost+=cst;
ID=totalCustomers;
items=itms;
cost=cst;
next=null;
}
public static int getTotalCustomers(){
return totalCustomers;
}
public static int getTotalItems(){
return totalItems;
}
public static int getTotalCost(){
return totalCost;
}
public int getID(){
return ID;
}
public int getItems(){
return items;
}
public int getCost(){
return cost;
}
public Customer getNext(){
return next;
}
public static void setTotalCustomers(int totalcustomers){
totalCustomers=totalcustomers;
}
public static void setTotalItems(int totalitems){
totalItems=totalitems;
}
public static void setTotalCost(int totalcost){
totalCost=totalcost;
}
public void setItems(int items){
this.items=items;
}
public void setCost(int cost){
this.cost=cost;
}
public void setID(int id){
ID=id;
}
public void setNext(Customer customer){
next=customer;
}
public boolean isEqualItemCost(){
return items==cost;
}
public String toString(){
return ID+" "+items+" "+cost;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote