mianelson367
mianelson367
25.04.2020 • 
Engineering

Cashier Class SpecificationThe Cashier class represents a supermarket cashier. A cashier has a name (name instance variable), a total amount of money collected(total instance variable) after processing a number of items, a number of items processed (numberOfItems instance variable), and adescription of each item that was processed (allItemsScanned instance variable). The declaration of each variable follows.private String name;private int total, numberOfItems;private StringBuffer allItemsScanned;The class methods are:1. Constructor - Takes a string as parameter. The parameter represents the cashier’s name. It will initialize instance variablesaccordingly. The method assigns a StringBuffer object to the allItemsScanned instance variable. The method will throw (with any message) if the parameter is null or its length is less than 3.2. Copy Constructor - Creates a copy where changes to the copy will not affect the original.3. processItem - Takes as parameters a string representing an item, and an integer representing its price. It will append the string tothe allItemsScanned StringBuffer and will increase the number of items. No separator will be added (e.g., a comma). The totalinstance variable must be adjusted accordingly. The method will not modify the instance variables if the string parameter is null,if the string parameter is the empty string or if the price is negative. The method always returns a reference to the current object.No exception will be thrown by this method.4. getName - get method for name.5. getTotal - get method for total.6. getNumberOfItems - get method for numberOfItems.7. getAllItemsScanned - get method for allItemsScanned. You must avoid privacy leaks.8. compareTo - It has a Cashier as parameter and returns an integer. This method will return:a. A negative value if the total value of the current object is less than the parameter.b. A positive value if the total value of the current object is greater than the parameter.c. If the current object and the parameter have the same value for total, the method will return:i. A negative value if the number of items of the current object is greater than the parameter.ii. A positive value if the number of items of the current object is less than the parameter.iii. 0 otherwise.

Solved
Show answers

Ask an AI advisor a question