Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1.  
  2. /**
  3. * This class simulates the sale of a retail item
  4. *
  5. * @author Adrian Sieroslawski
  6. * @version 1.0
  7. */
  8. public class CashRegister{
  9. public static final double TAX_RATE = 0.06;
  10.  
  11. private RetailItem item;
  12. private int quantitySold;
  13.  
  14. // Constructors
  15. public CashRegister() {
  16. item = new RetailItem();
  17. }
  18.  
  19. public CashRegister(String newItem, int newQuantitySold) {
  20. setItemSold(newItem);
  21. setQuantitySold(newQuantitySold);
  22.  
  23. item = new RetailItem(newItem, newQuantitySold);
  24. newQuantitySold = quantitySold;
  25. }
  26.  
  27. public CashRegister(RetailItem itemSold) {
  28. item = itemSold;
  29. }
  30.  
  31. //Accessors aka Getters
  32. public RetailItem getItemSold() {
  33. return item;
  34. }
  35.  
  36. public int getQuantitySold() {
  37. return quantitySold;
  38. }
  39.  
  40. //Mutators aka Setters
  41.  
  42. public void setQuantitySold(int quantity) {
  43. if(quantity >= 0 && quantity <= item.getNumberOfUnitsInStock()) {
  44. quantitySold = quantity;
  45. }
  46. }
  47.  
  48. public void setItemSold(String itemSold) {
  49. if(itemSold != null) {
  50. item = itemSold;
  51. } else {
  52. item = new RetailItem();
  53. }
  54. }
  55. // Calculation Methods
  56. public double calculateSubtotal() {
  57. double subTotal = getQuantitySold() * item.getItemPriceInCAD();
  58. return subTotal;
  59. }
  60.  
  61. public double calculateTax() {
  62. double totalTax = TAX_RATE * calculateSubtotal();
  63. return totalTax;
  64. }
  65.  
  66. public double calculateTotal() {
  67. double total = calculateSubtotal() + calculateTax();
  68. return total;
  69. }
  70.  
  71. public void printSalesReceipt() {
  72.  
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement