Question: PROJECT Using Java Classes: Retail Gift Card Application Objective To type a simple Java program, execute ( run ) the program for some particular values,

PROJECT Using Java Classes: Retail Gift Card Application

Objective To type a simple Java program, execute ( run ) the program for some particular values, observe the output and then modify the program.

PROJECT DESCRIPTION

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.

Type, compile and run the basic Java program that is shown in Figure 1 - 2 , which follows. Then compile and run your program, observe the output then modify the program.

Information About This Project

Gift cards are an important part of the retail shopping world. The typical gift card has many data items associated with it such as: the gift card number, the original card balance, the current balance, any expiration date as well as any type that the card may represent such as a store credit gift card.

PROJECT Using Java Classes: Retail Gift Card Application

Steps to Complete This Project

STEP 1 Open Eclipse or NetBeans

Open Eclipse or NetBeans and create a Java project with the following details.

For Project Name include: GiftCards

For the Main Class include: GiftCards

In your Java project, open a new class with this name: GiftCards

In your Code window for this class, shown below, copy the program code shown in Figure 1 below, in the appropriate places, except substitute your own name in place of Sammy Student.

Figure 1 Source Code for the Gift Cards Program

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();

Date myDate = new Date();

String myDateFormat = "MM/dd/yyyy";

SimpleDateFormat dtToday = new SimpleDateFormat(myDateFormat);

// 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: " + dtToday.format(myDate));

System.out.println(" Card Holder . . . " + holder);

System.out.println(" Card Amount . . . " + balance);

}

PROJECT Using Java Classes: Retail Gift Card Application

Figure 1 Source Code for the Gift Cards Program ( continued )

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: " + dtToday.format(myDate));

System.out.println(" Card Amount . . . " + balance);

}

}

In your Java project, open a new class with this name: TestGiftCards

In your Code window for this class, shown below, copy the program code shown in Figure 2 below, in the appropriate places, except substitute your own name in place of Sammy Student.

PROJECT Using Java Classes: Retail Gift Card Application

Figure 2 Source Code for the Test Gift Cards Program

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);

}

}

STEP 2 Build, Compile and Run the Program

From the menu select [ Run ] and click [ Run Project ] to run your app.

PROJECT Using Java Classes: Retail Gift Card Application

STEP 3 Test the Program

Once you have successfully compiled your program, review the output that appears in the message boxes that follow in Figure 2 . This represents a sample run of the program.

With the program running enter valid values in the input boxes that appear.

Observe your program output which will be similar to that given below, after you perform some modifications to the given starter code.

Figure 2 Initial Test Run(s)

Scenario I

[ Card Issued ]

Today's Date is: 11/08/2016

Card Holder . . . James

Card Number . . . 505

Card Amount . . . $75.00

Scenario II

[ Card Balance ]

Today's Date is: 11/10/2016

Deducted . . . . $10.00

Card Balance . . $40.00

Verify the quantities that appear in the message boxes or console window.

STEP 4 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.

Now 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

PROJECT Using Java Classes: Retail Gift Card Application

Also, 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 5 Submit Your Project

Once you have determined that your modified program is correctly displaying the required information, complete the submission process as follows:

Open MS Word and type a heading for a new document that includes your full name, course number, lab number and date.

Within the document paste snapshots of your modified program in action. Label the snapshots of your modified run with a reasonable description.

After your snapshot, paste in your finished source code as well copied in from your Java editor.

Submit your MS Word document, when complete.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!