Create a class named "CreditCard", that implementes this API. Start with the code below and write the Javadoc and methods as listed in the API. Use your UnitConverter.java
code as an example, but omit the static
from the method declarations.
public class CreditCard { public static final double DEFAULT_LIMIT = 5000.0; private String name; private int number; private double balance; private double limit; public CreditCard(int cardNum, String cardName) { name = cardName; number = cardNum; balance = 0.0; limit = DEFAULT_LIMIT; } }Generate your Javadoc using the command
javadoc CreditCard.java
and compare your Javadoc with the provided one. They should be exactly the same.
Use the following code to create a class named "CreditCardUI":
import java.io.PrintStream; import java.util.Scanner; /** This class provides the user interface to test CreditCard.java. */ public class CreditCardUI { 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(" 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; CreditCard cc = new CreditCard(123456, "Michelle Smith"); 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 == 'N') { out.println(cc.getName()); } else if (cmd == 'S') { out.println(cc); } else if (cmd == 'X') { exit = true; } } } }Use this code to test your
CreditCard
class. Ensure that you what this code does and how it works.