Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Creates an array of 5 GiftCards and tests the class GiftCard
- public class MyWallet {
- /**
- * sets the store name and the value for each giftCards and tests the class GiftCard
- *
- * @param args command line arguments, not used in this class.
- */
- public static void main(String[] args) {
- GiftCard[] cards = new GiftCard[5];
- cards[0] = new GiftCard("Safeway",100.0);
- cards[1] = new GiftCard("walgreen's");
- cards[2] = new GiftCard("Target",50.0);
- cards[3] = new GiftCard("Apple Store",2000.0);
- cards[4] = new GiftCard("Fry's",200.0);
- printGiftCards(cards);
- cards[0].addValue(100);
- cards[1].addValue(-9999);
- cards[2].purchase(13);
- cards[3].purchase(1632);
- cards[4].purchase(150);
- cards[4].purchase(51);
- printGiftCards(cards);
- double maxValue = -1.0;
- String store = null;
- for(int i = 0; i<5; i++){
- GiftCard giftCard = cards[i];
- double value = giftCard.getValue();
- if(value > maxValue){
- maxValue = value;
- store = giftCard.getStore();
- }
- }
- System.out.println(maxValue);
- }
- /**
- * Prints the store name and the value for each giftCard
- */
- public static void printGiftCards(GiftCard[] cards){
- for (int i=0; i<5; i++){
- GiftCard giftCard = cards[i];
- System.out.printf("%s\t%9.2f%n", giftCard.getStore(), giftCard.getStore());
- }
- }
- }
Add Comment
Please, Sign In to add comment