/* *************************************************************************** * (c)Copyright notice - 2003 - Uwe "Ed" Beltz, JD. * * All rights reserved. * * * * DISCLAIMER: The efforts including the development, research, and * * testing of the following program, and its effectiveness, are solely * * my effort in conjunction with training in INLS161 - Spring 2003. * * The author makes no warranty of any kind, expressed or implied, * * with regard to this, or any associated program. The author shall not * * be held liable in any event for incidental or consequential damages * * arising in connection with, or arising out of, the use, furnishing, * * or performance of this program. * *************************************************************************** */ import javax.swing.*; import java.awt.*; import java.text.DecimalFormat; /* This class is used to determine and report the credit standing of a person at the end of a given month. The input comes with pre-specified information from an account as provided by CreditCheckApplet */ public class CreditCheck { //Opens class "CreditCheck String outputNewBalance; //These are all needed to convert using twoDigits class String outputInitialBalance; String outputTotalCharges; String outputRemainingCredit; String outputNegativeBalance; String outputTotalCredits; String outputCreditLimit; String outputDerivedNewBalance; String CustomerName; //creates new String variable to be used in this class int AccountNumber = 0; //creates new integer variable to be used in this class double InitialBalance = 0.0; //creates new double value to be used in this class double TotalCharges = 0.0; //creates new double value to be used in this class double TotalCredits = 0.0; //creates new double value to be used in this class double CreditLimit = 0.0; //creates new double value to be used in this class double NewBalance = 0.0; //creates new double value to be used in this class double RemainingCredit = 0.0; //creates new double value to be used in this class double NegativeBalance = 0.0; //creates new double value to be used in this class double DerivedNewBalance = 0.0; public CreditCheck () //constructor method { } public void setCustomerName (String CName) /* Accepts String input variable called CName from CreditCheckApplet and changes it to Customer Name variable to be used in this class. I added this both to practice the skill of adding new methods and to allow myself to print out a customer record that seemed more customer friendly. */ { CustomerName = CName; } public void setAccountNumber (int actNo) /* Accepts Double input variable called actNo from CreditCheckApplet and changes it to AccountNumber variable to be used in this class */ { AccountNumber = actNo; } public void setInitialBalance (double initB) /* Accepts Double input variable called initB from CreditCheckApplet and changes it to InitialBalance variable to be used in this class */ { InitialBalance = initB; } public void setTotalCharges (double charges) /* Accepts Double input variable called charges from CreditCheckApplet and changes it to TotalCharges variable to be used in this class */ { TotalCharges = charges; } public void setTotalCredits (double credits) /* Accepts Double input variable called credits from CreditCheckApplet and changes it to TotalCredits variable to be used in this class */ { TotalCredits = credits; } public void setCreditLimit (double creditLimit) /* Accepts Double input variable called creditLimit from CreditCheckApplet and changes it to CreditLimit variable to be used in this class */ { CreditLimit = creditLimit; } public void showResult () /* This method processes the information carried over from the inputs of CreditCheckApplet from the methods above which have converted the variables into new variables that can be used, processed and stored in this class */ { DecimalFormat twoDigits; NewBalance = ((InitialBalance + TotalCharges) - TotalCredits); //defines new variable "NewBalance" RemainingCredit = CreditLimit - NewBalance; //defines new variable "RemainingCredit" NegativeBalance = NewBalance - CreditLimit; //defines new variable "NegativeBalance" /* The reason for the RemainingCredit and NegativeBalance is to remove the negative sign from the number, so I could add a negative before the dollar sign */ DerivedNewBalance = TotalCredits - (TotalCharges + InitialBalance); /* The reason for the DerivedNewBalance is to reove the negative sign from the output, in the situation where the customer overpaid his account and arrived to the end of the month with a negative balance. Don't want the negative in front of the dollar sign. */ twoDigits = new DecimalFormat ("0.00"); outputInitialBalance = twoDigits.format (InitialBalance); outputRemainingCredit = twoDigits.format (RemainingCredit); outputNegativeBalance = twoDigits.format (NegativeBalance); outputNewBalance = twoDigits.format (NewBalance); outputTotalCharges = twoDigits.format (TotalCharges); outputTotalCredits = twoDigits.format (TotalCredits); outputCreditLimit = twoDigits.format (CreditLimit); outputDerivedNewBalance = twoDigits.format (DerivedNewBalance); if (NewBalance < 0) // this report is for customers with a credit balance { JOptionPane.showMessageDialog (null, "Hi, " + CustomerName + ".\n" + "Your account has a credit balance.\n" + "Your beginning balance was $" + outputInitialBalance + "\n" + "Your charges for the month were $" + outputTotalCharges + "\n" + "This month you paid a total of $" + outputTotalCredits + "\n" + "The current balance of your account is -$" + outputDerivedNewBalance + "\n" + "Your credit line is $" + outputCreditLimit + "\n" + "Your remaining credit is $" + outputRemainingCredit); } else if (NewBalance > CreditLimit) /* This report is provided for customers who have overdrawn their account. */ { JOptionPane.showMessageDialog (null, "Hi, " + CustomerName + ".\n" + "Your account, " + AccountNumber + " is overdrawn by $" + outputNegativeBalance + "!!\n" + "Your beginning balance was $" + outputInitialBalance + "\n" + "Your charges for the month were $" + outputTotalCharges + "\n" + "This month you paid a total of $" + outputTotalCredits + "\n" + "The current balance of your account is $" + outputNewBalance + "\n" + "Your credit line is only $" + outputCreditLimit + "\n" + "YOUR ACCOUNT IS OVERDRAWN: PLEASE PAY IMMEDIATELY!!!"); } else if (NewBalance < CreditLimit) /* This report is for the customer who is in good standing. */ { JOptionPane.showMessageDialog (null, "Hi, " + CustomerName + ".\n" + "Your account is in good standing.\n" + "Your beginning balance was $" + outputInitialBalance + "\n" + "Your charges for the month were $" + outputTotalCharges + "\n" + "This month you paid a total of $" + outputTotalCredits + "\n" + "The current balance of your account is $" + outputNewBalance + "\n" + "Your credit line is $" + outputCreditLimit + "\n" + "Your remaining credit is $" + outputRemainingCredit); } else if (NewBalance == CreditLimit) /*This report is for those customers who have exactly reached their credit limit. */ { JOptionPane.showMessageDialog (null, "Hi, " + CustomerName + ".\n" + "Your account, " + AccountNumber + " has reached the credit limit!!\n" + "Your beginning balance was $" + outputInitialBalance + "\n" + "Your charges for the month were $" + outputTotalCharges + "\n" + "This month you paid a total of $" + outputTotalCredits + "\n" + "The current balance of your account is $" + outputNewBalance + "\n" + "Your credit line is $" + outputCreditLimit + "\n" + "Your remaining credit is $0.00\n" + "Please call the Credit department to see if you qualify for additional credit."); } } }