Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Represents a gift card
- public class GiftCard {
- private String storeName;
- private double value;
- /**
- * A constructor that takes the store name and the value as parameters.
- *
- * @param storeName name of the store
- * @param value how much the gift card has
- */
- public GiftCard(String storeName, double value){
- }
- /**
- * A constructor that takes the store name as a parameter and sets the value to 0.
- *
- * @param storeName
- */
- public GiftCard(String storeName){
- this(storeName, 0.0);
- }
- /**
- * Returns the current value of the CiftCard
- *
- * @return
- */
- public double getValue(){
- return value;
- }
- /**
- * Returns the name of the store that issued this GiftCard
- *
- * @return
- */
- public String getStore(){
- return storeName;
- }
- /**
- * Adds amount to the Value of this GiftCard if the amountToAdd is greater than 0.
- * Otherwise it does nothing.
- *
- * @param amountToAdd the amount to add
- */
- public void addValue(double amountToAdd){
- if (amountToAdd > 0.0){
- value = value + amountToAdd;
- }
- else{
- return;
- }
- }
- /**
- * Reduces the value by the amount of the purchase.
- * If amountOfPurchase is negative or greater than the value in the card, do nothing.
- *
- * @param amountOfPurchase the amount of purchase
- */
- public void purchase(double amountOfPurchase){
- if (amountOfPurchase < value || amountOfPurchase > 0){
- value = value - amountOfPurchase;
- }
- else{
- return;
- }
- }
- }
Add Comment
Please, Sign In to add comment