The problem will be triggered if employees check the highest sales product before having checkout for at least one successful checkout. ================================================================================== Please input your Worker ID for logging in the system... 1 Please input your Member ID for logging in the system... 0 ---Welcome to Morx Supermarket--- ---To continue, please proceed your actions--- Input (1) for accessing Inventory System Input (2) for accessing Checkout System Input (3) for accessing Sales System Input (4) for accessing Membership System Input (5) for switching member Input (6) to exit 3 ---Hi ON9, Welcome to Sales System. ------Input commands for further management--- Input (1) for Listing Sales Input (2) for checking Total income Input (3) for checking highest sales Product Input (4) for exit 3
The problem has been solved by adding exceptions for case which POS hasn't handled any transactions. ================================================================================public void checkForHighestSalesProductAndPercentage() { try { if (salesFunction.checkSalesIsEmpty()) { throw new ExNoSalesExists(); } else { int daysUnit = getCheckSalesDaysUnit(); int ageGroupUnit = getCheckAgeGroupDigit(); boolean ageFilter = (ageGroupUnit == 0) ? false : true; Product product = salesFunction.printHighestSalesProduct(daysUnit, ageFilter, ageGroupUnit); if (product == null) { throw new ExNoSalesInSelectedAge(); } else { double percentage = salesFunction.getSalesPercentageForProduct(daysUnit, product, ageFilter, ageGroupUnit, salesFunction.getTotalSalesNum()); System.out.printf("The highest sales product for %s is %s\n", tools.returnStrforMoments(daysUnit), product.getName()); System.out.printf("The Sales Percentage for %s in %s is %.2f %%\n", product.getName(), tools.returnStrforMoments(daysUnit), percentage); } } } catch (ExNoSalesExists e) { System.out.println(e.getMessage()); } catch (ExNoSalesInSelectedAge e) { System.out.println(e.getMessage()); } } ================================================================================ Please input your Worker ID for logging in the system... 1 Please input your Member ID for logging in the system... 1234 ---Welcome to Morx Supermarket--- ---To continue, please proceed your actions--- Input (1) for accessing Inventory System Input (2) for accessing Checkout System Input (3) for accessing Sales System Input (4) for accessing Membership System Input (5) for switching member Input (6) to exit 3 ---Hi ON9, Welcome to Sales System. ------Input commands for further management--- Input (1) for Listing Sales Input (2) for checking Total income Input (3) for checking highest sales Product Input (4) for exit 3 *** No Sales Exists! ***