Check09A - int rejected = 0, transactionCount = 0; while...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import type.lib.*; import java.io.PrintStream; import java.util.Scanner; i public class Check09A { public static void main(String[] args) { PrintStream out = System.out; Scanner in = new Scanner (System.in); out.print("Credit or Reward card? [C or R] . .. "); String buffer = in.nextLine(); final int ANYINT = 111111; final String ANYNAME = "AAAAA", C = "C"; CreditCard either = (buffer.contains(C)) ? new CreditCard(ANYINT, ANYNAME) : new RewardCard(ANYINT, ANYNAME); out.println("Enter the transactions of this card"); out.println("(0ne per line, empty line=sentinel)");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int rejected = 0, transactionCount = 0; while (!(buffer = in.nextLine()).equals("")) { double value = Double.parseDouble(buffer.substring(1)); if ((buffer.substring(0, 1).toUpperCase()).contains(C)) { if (!either.charge(value)) { out.println("Failed!"); rejected += 1; } } else { either.pay(value); } transactionCount += 1; } out.println("Transaction Count = " + transactionCount); out.println("Rejected Transactions = " + rejected); out.printf("Card balance = %.2f%n", either.getBalance()); } }...
View Full Document

Ask a homework question - tutors are online