Enter your Credit Card Account number, Balance owed to the Credit Card, amount of New Charges, amount of New Credits, and the Card's Credit Limit. The Applet will tell you what is now owed on the Credit Card and if you have exceeded the Card's Credit Limit.

Credit.java demonstrates boolean

// class Credit // Author: Deitel/Deitel // Book: Java How to Program, 2nd Edition // Exercise 2.12 Solution // Program monitors accounts import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Credit extends Applet implements ActionListener { TextField accountInput, oldBalanceInput; TextField chargeInput, creditInput, limitInput; int account, newBalance; int oldBalance, credits, creditLimit, charges; boolean exceeded; Label accountLabel, oldLabel; Label chargeLabel, creditLabel, limitLabel; public void init() { setSize(250,300); accountLabel = new Label( "Enter Account:" ); oldLabel = new Label( "Enter Balance: " ); chargeLabel = new Label( "Enter Charges: " ); creditLabel = new Label( "Enter Credits: " ); limitLabel = new Label( "Enter Credit Limit: " ); accountInput = new TextField( 5 ); oldBalanceInput = new TextField( 5 ); chargeInput = new TextField( 5 ); creditInput = new TextField( 5 ); limitInput = new TextField( 5 ); limitInput.addActionListener( this ); add( accountLabel ); add( accountInput ); add( oldLabel ); add( oldBalanceInput ); add( chargeLabel ); add( chargeInput ); add( creditLabel ); add( creditInput ); add( limitLabel ); add( limitInput ); } public void actionPerformed( ActionEvent e ) { exceeded = false; account = Integer.parseInt( accountInput.getText() ); oldBalance = Integer.parseInt( oldBalanceInput.getText() ); charges = Integer.parseInt( chargeInput.getText() ); credits = Integer.parseInt( creditInput.getText() ); creditLimit = Integer.parseInt( limitInput.getText() ); newBalance = oldBalance + charges - credits; showStatus( "New balance is " + newBalance ); if ( newBalance > creditLimit ) exceeded = true; repaint(); } public void paint( Graphics g ) { if ( exceeded == true ) g.drawString( " CREDIT LIMIT EXCEEDED. ", 2, 149 ); } }