Question
Write a program that uses two classes to demonstrate object - oriented programming. Your program will define a parent class named GiftCards and a test
Write a program that uses two classes to demonstrate object - oriented programming. Your program will define a parent class named GiftCards and a test class named TestGiftCards . Class GiftCards will be used to obtain and display gift card data such as: the gift card holders name the gift card number the gift card opening balance the year of issue the expiration date Mutator and accessor methods are incorporated in the definition of class GiftCards to obtain and display information with the class data members. Class TestGiftCards will be used to implement the GiftCards class by processing the following tasks: obtain and display the gift card holders name and card number obtain and display gift card opening balance obtain and display other important gift card information subtract any amount from the card balance when the gift card is used display the current gift card balance, after the card is used An object of class GiftCards will be instantiated in class TestGiftCards . The object will utilize both data members and member functions of its class. Basically, your program is outlined in the given starter code statements shown within Figure 1 , which follows. Review the starter code to understand the mechanisms of the interactions between the two classes. Perform any modifications according to this projects instructions. import java.text.DateFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Date; //Sammy Student public class GiftCards { static NumberFormat nf = NumberFormat.getCurrencyInstance(); DateFormat dateForm = new SimpleDateFormat("MM/dd/yyyy"); Date today = new Date(); // define the class data members public boolean expires; private double balance; public int cardNum; private char cardType; public String issueDate; private String holder; // define the member methods // default constructor public GiftCards() {} // overloaded constructor public GiftCards(String n, double amt) { holder = n; balance = amt; } public void IssueGiftCard() { System.out.println(""); System.out.println(" Card Issued"); System.out.println(" Today's Date is: " + dateForm.format(today)); System.out.println(" Card Holder . . . " + holder); System.out.println(" Card Amount . . . " + balance); } public double getBalance() { return balance; } public void setBalance(double b) { balance = b; } public String getHolder() { return holder; } public void setHolder(String h) { holder = h; } public void printCurrentGiftCardInfo(double spend) { System.out.println(""); System.out.println(" Card Balance"); System.out.println(" Today's Date is: " + dateForm.format(today)); System.out.println(" Card Amount . . . " + balance); } } In your java project, open anew class called: TestGiftCards Copy the following code into the window for that class import javax.swing.JOptionPane; public class TestGiftCards //Sammy Student { public static void main(String[] args) { GiftCards gc = new GiftCards("", 0.0); // display opening message String message = "welcome"; JOptionPane.showMessageDialog(null, "Message: " + message, "Message", JOptionPane.PLAIN_MESSAGE); // set the gift card holder's name String str = JOptionPane.showInputDialog(null, "gift card holder's name : "); gc.setHolder(str); // obtain the gift card number str = JOptionPane.showInputDialog(null, "gift card number : "); gc.cardNum = Integer.parseInt(str); // set the gift card amount str = JOptionPane.showInputDialog(null, "gift card amount : "); gc.setBalance(Double.parseDouble(str)); // issue the gift card gc.IssueGiftCard(); // use the gift card double useCard = 0; str = JOptionPane.showInputDialog(null, "deduct amount from card : "); useCard = Double.parseDouble(str); // verify amount to deduct will not yield negative balance // print current card balance gc.printCurrentGiftCardInfo(useCard); } } modify the program as follows Modify the Program Once your program runs successfully you can now modify the original starter code such that either or both the parent class and the test class will display any required currency data with a dollar sign $ and two decimal places. Also, ensure that the gift card number is displayed to the program user. [ Card Issued ] Today's Date is: 11/08/2016 Card Holder . . . James Card Number . . . 505 Card Amount . . . $75.00 Also, modify the program such that when the card is used the new balance of the card is displayed to the user. Of course, be sure to prevent spending more than the current balance of the gift card. [ Card Balance ] Today's Date is: 11/10/2016 Deducted . . . . $10.00 Card Balance . . $40.00 Test your modified program. Extra Credit: use the included expires class GiftCards data member and supplement the program such that an expiration date is given to the gift card when the card is issued. [ Card Issued ] Today's Date is: 11/08/2016 Card Holder . . . James Card Number . . . 506 Card Amount . . . $75.00 Expires . . . . . 2020 Extra Credit: use the included cardType class GiftCards data member and supplement the program such that a card type is assigned to the gift card. The type could be, for example, ' S ' for store credit or ' R ' for a regular or purchased gift card.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started