Directory:Derek Elder/Programs/CheckingAccount1

MyWikiBiz, Author Your Legacy — Saturday December 21, 2024
Jump to navigationJump to search

CheckingAccount.java

//*******************************************************************
//  CheckingAccount Class       Author: Derek Elder
//********************************************************************
public class CheckingAccount
{
	private double balance;
	private double totalServiceCharge;
 
	public double getBalance()
	{
		return balance;
	}
	public double setBalance(double currentBalance, double tCode)
	{
            if(tCode == 1 || tCode == 0)
		balance -= currentBalance;
            else //if(tCode == 2)
                balance += currentBalance;
            return balance;
	}
	public double getServiceCharge()
	{
		return totalServiceCharge;
	}
        public double setServiceCharge(double currentServiceCharge)
	{
		totalServiceCharge += currentServiceCharge;
                return totalServiceCharge;
	}
	public CheckingAccount(double currentBalance, double currentServiceCharge)
	{
		balance = currentBalance;
		totalServiceCharge = currentServiceCharge;
	}
}

Main.java

//*******************************************************************
//  Program 1       Author: Derek Elder
//********************************************************************

import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Main
{
    public static void main(String[] args)
    {
        int tCode = 0;
	String stringBalance, stringTCode, stringTransAmt, message;
        double balance, transAmt, charge, balanceBeforeCharge;
        boolean done = false;
	boolean below500 = false;
        charge = 0.00;
	stringBalance = JOptionPane.showInputDialog("Enter your initial balance: ");
	balance = Double.parseDouble(stringBalance);
        CheckingAccount account = new CheckingAccount(balance, charge);

        while(!done)
        {
            stringTCode = JOptionPane.showInputDialog("Enter the trans code: ");
            tCode = Integer.parseInt(stringTCode);
            DecimalFormat fmt = new DecimalFormat ("0.00"); //Round to two decimal places
            if(tCode == 1)
            {
                stringTransAmt = JOptionPane.showInputDialog("Enter the trans amount: ");
                transAmt = Double.parseDouble(stringTransAmt);
                account.setBalance(transAmt, tCode);
                if(account.getBalance() < 0.00)
                {
                    if(below500 == true)
                    {
                        charge = 10.15; //Cost of Check + Below $0 charge
                        account.setServiceCharge(charge);
                        message = "Transaction : Check in the amount of $" + fmt.format(transAmt) + "\n" +
                                "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                                "Service charge : Check -- charge $0.15" + "\n" +
                                "Warning : Balance below $50.00" + "\n" +
                                "Service charge : Below $0 -- charge $10.00" + "\n" +
                                "Total service charge : $" + fmt.format(account.getServiceCharge());
                        JOptionPane.showMessageDialog(null, message);
                    }
                    else
                    {
                        charge = 5.15; //Cost of Check + Below $500 charge
                        account.setServiceCharge(charge);
                        message = "Transaction : Check in the amount of $" + fmt.format(transAmt) + "\n" +
                                "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                                "Service charge : Check -- charge $0.15" + "\n" +
                                "Service charge : Below $500.00 -- charge $5.00" + "\n" +
                                "Total service charge : $" + fmt.format(account.getServiceCharge());
                        JOptionPane.showMessageDialog(null, message);
                        below500 = true;
                    }

                }
                else if(account.getBalance() < 500.00 && below500 == false)
                {
                    charge = 5.15; //Cost of Check + Below $500 charge
                    account.setServiceCharge(charge);
                    below500 = true;
                    if(account.getBalance() < 50.00)
                    {
                        message = "Transaction : Check in the amount of $" + fmt.format(transAmt) + "\n" +
                            "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                            "Service charge : Check -- charge $0.15" + "\n" +
                            "Warning : Balance below $50.00" + "\n" +
                            "Total service charge : $" + fmt.format(account.getServiceCharge());
                        JOptionPane.showMessageDialog(null, message);
                    }
                    else
                    {
                        message = "Transaction : Check in the amount of $" + fmt.format(transAmt) + "\n" +
                                "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                                "Service charge : Check -- charge $0.15" + "\n" +
                                "Service charge : Below $500.00 -- charge $5.00" + "\n" +
                                "Total service charge : $" + fmt.format(account.getServiceCharge());
                        JOptionPane.showMessageDialog(null, message);
                    }
                }
                else
                {
                    charge = 0.15;
                    account.setServiceCharge(charge);
                    if(account.getBalance() < 50.00)
                    {
                        message = "Transaction : Check in the amount of $" + fmt.format(transAmt) + "\n" +
                                "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                                "Service charge : Check -- charge $0.15" + "\n" +
                                "Warning : Balance below $50.00" + "\n" +
                                "Total service charge : $" + fmt.format(account.getServiceCharge());
                        JOptionPane.showMessageDialog(null, message);
                    }
                    else
                    {
                        message = "Transaction : Check in the amount of $" + fmt.format(transAmt) + "\n" +
                                "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                                "Service charge : Check -- charge $0.15" + "\n" +
                                "Total service charge : $" + fmt.format(account.getServiceCharge());
                        JOptionPane.showMessageDialog(null, message);
                    }
                }
                done = false;
            }
            else if(tCode == 2)
            {
                stringTransAmt = JOptionPane.showInputDialog("Enter the trans amount: ");
                transAmt = Double.parseDouble(stringTransAmt);
                charge = 0.10;
                account.setServiceCharge(charge);
                account.setBalance(transAmt, tCode);
                if(account.getBalance() <= 50.00)
                {
                    message = "Transaction : Check in the amount of $" + fmt.format(transAmt) + "\n" +
                            "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                            "Service charge : Deposit -- charge $0.10" + "\n" +
                            "Warning : Balance below $50.00" + "\n" +
                            "Total service charge : $" + fmt.format(account.getServiceCharge());
                    JOptionPane.showMessageDialog(null, message);
                }
                else
                {
                    message = "Transaction : Deposit in the amount of $" + fmt.format(transAmt) + "\n" +
                            "Current Balance : $" + fmt.format(account.getBalance()) + "\n" +
                            "Service charge : Deposit -- charge $0.10" + "\n" +
                            "Total service charge : $" + fmt.format(account.getServiceCharge());
                    JOptionPane.showMessageDialog(null, message);
                }
                done = false;
            }
            else //tCode = 0
            {
                balanceBeforeCharge = account.getBalance();
                charge = account.getServiceCharge();
                account.setBalance(charge, tCode);
                message = "Transaction : End" + "\n" +
                          "Current Balance : $" + fmt.format(balanceBeforeCharge) + "\n" +
                          "Total service charge : $" + fmt.format(account.getServiceCharge()) + "\n" +
                          "Final Balance : $" + fmt.format(account.getBalance());
                JOptionPane.showMessageDialog(null, message);
                done = true;
            }
        }
        message = "End of program.";
        JOptionPane.showMessageDialog(null, message);
    }
}