The TestApp class in the example package contains examples and presents the main test cases but not all. Exceptions are thrown using the OException class; only the specified checks must be carried out and not all possible ones. If a method throws an exception there is no change in the data present in the main class. Suggestions: look at TestApp to understand the requirements of methods; every time you have implemented a method, run TestApp to check the result.
The JDK documentation is accessible at URL https://oop.polito.it/api/.
Method int getNumberOfProducts (String productType) throws OException gives the number of products belonging to the given productType; an exception is thrown if the productType does not exist.
Method groupingProductTypeByPrices() groups the product types by increasing price. The product types with same price are listed in alphabetical order.
Customers' orders can be placed using method int customerOrder(String customer, String ptpn, int discount) throws OException
that has 3 parameters: the customer, the products with the relative quantity, and the discount requested (which may also be 0).
An example that can be found in TestApp is this one: customerOrder("ctr1", "tableX:2 loungeChair:1", 20); this call
allows customer ctr1 to buy two tables (tableX is the name of the product type) and one loungeChair, a discount of 20 is requested.
This string has two substrings separated by one space; a substring consists of a product type and the number of product items
separated by :.
The result is the total price: it consists of the sum of the prices of the products minus the discount (if greater than 0).
Possible problems to be managed:
1) If not all the number of products requested are available the result is 0; the customer doesn't buy anything.
2) If the requested discount exceeds the available discount for the customer, an exception is thrown.
In case of no problems, the number of products available is reduced by the number of products requested by the customer order.
In addition, the available discount is decremented by the requested discount;
the available discount is the discount that can be used by the next customerOrder() call.
Method int getDiscountAvailable (String customer) gives the available discount for the customer (it could be 0).
Method int getScoreFromProductType (String customer, String productType) throws OException shows the score assigned by the customer to the indicated type of product. An exception is thrown if the customer has not assigned a score to that product type.
Method groupingCustomersByScores(String productType) groups customers by increasing scores relating to the type of product indicated. Customers are listed in alphabetical order.
Method largestExpenseForCustomer () provides the largest expense in an individual order for each customer (in increasing order). Customers with no orders are not reported.