Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. /**
  2. * Simulates a grocery receipt generated by a clerk
  3. *
  4. * @author Name Van period 3
  5. *
  6. */
  7. public class GroceryReceipt {
  8. private Employee clerk;// Employee object representing the clerk generating
  9. // the receipt
  10. private String receipt;// List of items
  11. private double total;// Total price
  12.  
  13. /**
  14. * Initializes the clerk to the passed in employee, the receipt to an empty
  15. * string and total to 0
  16. *
  17. * @param clerk
  18. * - employee generating this receipt
  19. */
  20. public GroceryReceipt(Employee clerk) {
  21. // Your code goes here
  22. this.clerk = clerk;
  23. receipt = "";
  24. total = 0;
  25. }
  26.  
  27. /**
  28. * Returns the total amount on this receipt in dollars and cents
  29. *
  30. * @return total amount
  31. */
  32. public double getTotal() {
  33. // Your code goes here
  34. return total;
  35. }
  36.  
  37. /**
  38. * Returns the clerk generating the information
  39. *
  40. * @return clerk
  41. */
  42. public Employee getClerk() {
  43. // Your code goes here
  44. return clerk;
  45. }
  46.  
  47. /**
  48. * Returns the list of items
  49. *
  50. * @return receipt
  51. */
  52. public String getReceipt() {
  53. // Your code goes here
  54. return receipt;
  55. }
  56.  
  57. /**
  58. * Adds the given item to the receipt Updates the total by adding in the the
  59. * items price
  60. *
  61. * @param i
  62. * - grocery item to be added
  63. */
  64. public void add(Item i) {
  65. // Your code goes here
  66. receipt = receipt + i.toString();
  67. total = i.getPrice() + total;
  68. }
  69.  
  70. /**
  71. * Returns the value passed as a string in the dollar and cents format
  72. * ####.##
  73. *
  74. * @param value
  75. * - value to be converted to dollar and cents format
  76. * @return String in dollar and cents format
  77. */
  78. public String valueToString(double value) {
  79. // Your code goes here
  80. int convert = (int)(value * 100);
  81. if(convert == 0.0){return "0.00";}else{
  82. double convert2 = ((double)convert)/100;
  83. return "" + convert2;}
  84. }
  85.  
  86. /**
  87. * Returns a string with list of items (one per line) and total receipt
  88. * amount
  89. *
  90. * @return a string with list of items and total receipt amount
  91. */
  92.  
  93. public String toString() {
  94. // Your code goes here
  95. return receipt + "\nTotal: $" + valueToString(total);
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement