Guest User

Untitled

a guest
May 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. //Creates an array of 5 GiftCards and tests the class GiftCard
  2. public class MyWallet {
  3.  
  4.  
  5.  
  6. /**
  7. * sets the store name and the value for each giftCards and tests the class GiftCard
  8. *
  9. * @param args command line arguments, not used in this class.
  10. */
  11. public static void main(String[] args) {
  12. GiftCard[] cards = new GiftCard[5];
  13. cards[0] = new GiftCard("Safeway",100.0);
  14. cards[1] = new GiftCard("walgreen's");
  15. cards[2] = new GiftCard("Target",50.0);
  16. cards[3] = new GiftCard("Apple Store",2000.0);
  17. cards[4] = new GiftCard("Fry's",200.0);
  18. printGiftCards(cards);
  19.  
  20. cards[0].addValue(100);
  21. cards[1].addValue(-9999);
  22. cards[2].purchase(13);
  23. cards[3].purchase(1632);
  24. cards[4].purchase(150);
  25. cards[4].purchase(51);
  26. printGiftCards(cards);
  27.  
  28. double maxValue = -1.0;
  29. String store = null;
  30. for(int i = 0; i<5; i++){
  31. GiftCard giftCard = cards[i];
  32. double value = giftCard.getValue();
  33. if(value > maxValue){
  34. maxValue = value;
  35. store = giftCard.getStore();
  36. }
  37. }
  38. System.out.println(maxValue);
  39. }
  40.  
  41. /**
  42. * Prints the store name and the value for each giftCard
  43. */
  44. public static void printGiftCards(GiftCard[] cards){
  45. for (int i=0; i<5; i++){
  46. GiftCard giftCard = cards[i];
  47. System.out.printf("%s\t%9.2f%n", giftCard.getStore(), giftCard.getStore());
  48. }
  49. }
  50.  
  51.  
  52. }
Add Comment
Please, Sign In to add comment