Develop a Java application that will determine whether a department-store customer has exceeded
the credit limit on a charge account. For each customer, the following facts are available:
a) account number,
b) balance at the beginning of the month,
c) total of all items charged by the customer this month,
d) total of all credits applied to the customer’s account this month and
e) allowed credit limit.
The program should input each of these facts from input dialogs as integers, calculate the new balance
(= beginning balance + charges – credits), display the new balance and determine whether the
new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded,
the program should display the message “Credit limit exceeded.”
// Program monitors accounts.
import java.awt.*;
import javax.swing.JOptionPane;
public class Credit {
public static void main( String args[] )
{
String inputString, // user input
resultsString, // result String
creditStatusString; // credit status
int account, // account number
oldBalance, // starting balance
charges, // total charges
credits, // total credits
creditLimit, // allowed credit limit
newBalance; // new balance
inputString = JOptionPane.showInputDialog(
“Enter Account Number:” );
account = Integer.parseInt( inputString );
inputString = JOptionPane.showInputDialog( “Enter Balance: ” );
oldBalance = Integer.parseInt( inputString );
inputString = JOptionPane.showInputDialog( “Enter Charges: ” );
charges = Integer.parseInt( inputString );
inputString = JOptionPane.showInputDialog( “Enter Credits: ” );
credits = Integer.parseInt( inputString );
inputString = JOptionPane.showInputDialog( “Enter Credit Limit: ” );
creditLimit = Integer.parseInt( inputString );
newBalance = oldBalance + charges – credits;
resultsString = “New balance is ” + newBalance;
if ( newBalance > creditLimit )
creditStatusString = “CREDIT LIMIT EXCEEDED”;
else
creditStatusString = “Credit Report”;
JOptionPane.showMessageDialog( null, resultsString,
creditStatusString, JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
} // end method main
} // end class Credit
