Guest User

Untitled

a guest
May 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. //Represents a gift card
  2. public class GiftCard {
  3.  
  4. private String storeName;
  5. private double value;
  6.  
  7. /**
  8. * A constructor that takes the store name and the value as parameters.
  9. *
  10. * @param storeName name of the store
  11. * @param value how much the gift card has
  12. */
  13. public GiftCard(String storeName, double value){
  14. }
  15.  
  16. /**
  17. * A constructor that takes the store name as a parameter and sets the value to 0.
  18. *
  19. * @param storeName
  20. */
  21. public GiftCard(String storeName){
  22. this(storeName, 0.0);
  23. }
  24.  
  25. /**
  26. * Returns the current value of the CiftCard
  27. *
  28. * @return
  29. */
  30. public double getValue(){
  31. return value;
  32. }
  33.  
  34. /**
  35. * Returns the name of the store that issued this GiftCard
  36. *
  37. * @return
  38. */
  39. public String getStore(){
  40. return storeName;
  41. }
  42.  
  43. /**
  44. * Adds amount to the Value of this GiftCard if the amountToAdd is greater than 0.
  45. * Otherwise it does nothing.
  46. *
  47. * @param amountToAdd the amount to add
  48. */
  49. public void addValue(double amountToAdd){
  50. if (amountToAdd > 0.0){
  51. value = value + amountToAdd;
  52. }
  53. else{
  54. return;
  55. }
  56. }
  57.  
  58. /**
  59. * Reduces the value by the amount of the purchase.
  60. * If amountOfPurchase is negative or greater than the value in the card, do nothing.
  61. *
  62. * @param amountOfPurchase the amount of purchase
  63. */
  64. public void purchase(double amountOfPurchase){
  65. if (amountOfPurchase < value || amountOfPurchase > 0){
  66. value = value - amountOfPurchase;
  67. }
  68. else{
  69. return;
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment