willieshi232

Untitled

Feb 25th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. 10.
  2.  
  3. public class DiscountBill extends GroceryBill
  4. {
  5.  
  6. private boolean preferred;
  7. private int numDiscountedItems;
  8. private double discountAmount;
  9. private double total;
  10. private double discountPercent;
  11.  
  12. public DiscountBill(Employee name, boolean pref)
  13. {
  14. super(name);
  15. preferred = pref;
  16. }
  17.  
  18. public int getDiscountCount()
  19. {
  20. for(int i = 0; i < itemsInGroceryList.size(); i++)
  21. {
  22. if(itemsInGroceryList.get(i).getDiscount() > 0)
  23. {
  24. numDiscountedItems++;
  25. }
  26. }
  27. return numDiscountedItems;
  28. }
  29.  
  30. public double getDiscountAmount()
  31. {
  32.  
  33. for(int i = 0; i < itemsInGroceryList.size(); i++)
  34. {
  35. if(itemsInGroceryList.get(i).getDiscount() > 0)
  36. {
  37. discountAmount = discountAmount + itemsInGroceryList.get(i).getDiscount();
  38. }
  39. }
  40. return discountAmount;
  41. }
  42.  
  43. public double getTotal()
  44. {
  45. if(isPreferredShopper == true)
  46. {
  47. total = super.getTotal() - discountAmount;
  48. return total;
  49. }
  50. else{
  51. total = super.getTotal();
  52. return total;
  53. }
  54. }
  55.  
  56. public double getDiscountPercent(){
  57. discountPercent = (1 - (total/super.getTotal())) * 100;
  58. return discountPercent;
  59. }
  60. }
  61.  
  62.  
  63. 15.
  64.  
  65. Public class Octagon implements Shape
  66. {
  67. private double length;
  68.  
  69. public Rectangle(double iniLength)
  70. {
  71. length = iniLength;
  72. }
  73. public double getArea()
  74. {
  75. return 2*(1+Math.sqrt(2))*length*length;
  76. }
  77. public double getPerimeter()
  78. {
  79. return 8*length;
  80. }
  81. }
  82.  
  83.  
  84.  
  85. 14.
  86.  
  87. Public boolean Equals(Rectangle A)
  88. {
  89. if (width = A.width && height = A.height)
  90. {
  91. return true;
  92. }
  93. else
  94. {
  95. return false;
  96. }
  97. }
  98.  
  99. Public boolean Equals(Circle A)
  100. {
  101. if (radius = A.radius)
  102. {
  103. return true;
  104. }
  105. else
  106. {
  107. return false;
  108. }
  109. }
  110. Public boolean Equals(Triangle pass)
  111. {
  112. if (a = pass.a && b = pass.b && c = pass.c)
  113. {
  114. return true;
  115. }
  116. else
  117. {
  118. return false;
  119. }
  120. }
  121.  
  122.  
  123.  
  124. 13.
  125.  
  126. Public boolean Equals(Cash A)
  127. {
  128. if (amount = A.amount)
  129. {
  130. return true;
  131. }
  132. else
  133. {
  134. return false;
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment