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

Write a class for modeling a customer. A customer knows its arrival time, its in

ID: 3852386 • Letter: W

Question

Write a class for modeling a customer. A customer knows its arrival time, its initial number of items, as well as the number of items remaining to be processed. The maximum number of items per customer is (MAX_NUM_ITEMS). Make sure you identified instance variables and class variables. The constructor has a single parameter. It specifies the arrival time. The initial number of items is determined when the object is first created using the following formula: MAX_NUM_ITEMS * Math.random() + 1 Since, Math.random() generates a random number greater than or equal to 0.0 and less than 1.0, the expression MAX_NUM_ITEMS * Math.random() generates a number greater than or equals to 0.0 and less than MAX_NUM_ ITEMS, adding 1 ensures that the number of items is greater than or equals to 1.0 but lower than MAX_NUM_ITEMS + 1. This real value is then converted to an int, in the range 1 to MAX_NUM_ITEMS (here, 1 wanted to make sure that no customer would show up empty handed). The instance methods of a customer include: int getArrivalTiirie() returns the arrival time: int getNumberOfltems() returns the number of items remaining to be processed: int getNumberOfServedltems() returns the number of items that have been processed: serve() decrements by one the number of items of this customer.

Explanation / Answer

Hi, There are no class variables in this, because all of the variables defined belong to a particular customer,

class variable means a variable that is constant to all its objects,

i have added the required functionality and commented the code to help you understand.

public class Customer {

public String arrivaltime;

public int initialitems;

public int remainingitems;

public String getArrivaltime() { // get arrival time function

return arrivaltime;

}

public int getNUmberOfItems() {// number of items yet to be processed

return remainingitems;

}

public int getNumberOfServedItems() {// served items would be total minus remaining items

return this.initialitems-this.remainingitems;

}

public Customer(String arrivaltime) { //constructor, initializes the items at the time of object creation

this.arrivaltime = arrivaltime;

this.initialitems= (int) (this.MAX_NUM_ITEMS* Math.random() +1); // adding cast to convert double to int

}

public void serve() // decrements the number of items

{

this.initialitems--;

}

public int MAX_NUM_ITEMS= 100; // you can change this to how much you want

}

Thumbs up if this was helpful, otherwise let me know in comments.

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