CSE 1030 A, Summer 2013

Your Own (Reward) Credit Card

 

Your Task

Create a class named "RewardCard", that implementes this API. Note that RewardCard extends CreditCard. When writing your code make use of the inherited features by using super when applicable.

If you do not have your CreditCard class available, download this jar file and remember its location. In Eclipse, add the jar to your build path (goto Project > Properties > Java Build Path > Libraries > Add External JARs...). Navigate to the location of the jar, select it, and click "Open".

Generate your Javadoc using the command javadoc RewardCard.java and compare your Javadoc with the provided one. They should be exactly the same.

Use the following code to create a class named "RewardCardUI":

import java.io.PrintStream;
import java.util.Scanner;

/**	This class provides the user interface to test RewardCard.java.
 */
public class RewardCardUI
{
	public static void main(String[] args)
	{
		PrintStream out = System.out;
		Scanner in = new Scanner(System.in);
		
		out.println("Commands:");
		out.println(" C to charge");
		out.println(" P to pay");
		out.println(" L to set limit");
		out.println(" B to get balance");
		out.println(" R to get reward points balance");
		out.println(" N to get name");
		out.println(" S to get toString output");
		out.println(" X to exit");
		out.println("For example,\n > C 500.00\nwill charge $500 to the card");
		
		boolean exit = false;
		char cmd;
		double value;
		RewardCard cc = new RewardCard(123456, "Katrina Brown");
		while (!exit)
		{
			out.print("> ");
			cmd = in.next().toUpperCase().charAt(0);
			if (cmd == 'C')
			{
				value = in.nextDouble();
				out.println(cc.charge(value) ? "done" : "failed");
			}
			else if (cmd == 'P')
			{
				value = in.nextDouble();
				out.println(cc.pay(value) ? "done" : "failed");
			}
			else if (cmd == 'L')
			{
				value = in.nextDouble();
				out.println(cc.setLimit(value) ? "done" : "failed");
			}
			else if (cmd == 'B')
			{
				out.println(cc.getBalance());
			}
			else if (cmd == 'R')
			{
				out.println(cc.getPointsBalance());
			}
			else if (cmd == 'N')
			{
				out.println(cc.getName());
			}
			else if (cmd == 'S')
			{
				out.println(cc);
			}
			else if (cmd == 'X')
			{
				exit = true;
			}
		}
	}
}
Use this code to test your RewardCard class. Ensure that you know what this code does and how it works.

 

 

 

--- End of Exercise ---