mercredi 26 septembre 2018

If else statement not calling isServiceCharge() method?

I am almost finished with this bank account program. I have a call to calculateSavings() method or calculateCheckings() method. If the currentBalance is less than the required minSavings or minChecking I have an else statement to call the isServiceCharge() method to deduct a fee. The program is not giving me errors but if the user inputs a currentBalance that is less than the required amount for minChecking or minSavings the JOptionPane is not showing the output. The inputs still work but there is no output popping up. Everything else works fine such as adding interest, but deducting a fee in the service charge isn't. How can I fix this.

Main class

package com.company;

import javax.swing.*;

public class Main
{


public static void main(String[] args)
{
    {
        BankAccount myBank = new BankAccount();

        myBank.calculateNewBalance();
    }

}
}

BankAccount class

package com.company;

import javax.swing.*;

public class BankAccount

{
private int accountNumber;
private String accountType;
private double minSavings = 2500.00;
private double minChecking = 1000.00;
private double currentBalance;


public BankAccount()
{

    accountNumber = Integer.parseInt(JOptionPane.showInputDialog("Please enter your account number"));
    accountType = JOptionPane.showInputDialog("Please enter your account type");
    currentBalance = Double.parseDouble(JOptionPane.showInputDialog("Please enter your current balance."));

}

public int getAccountNumber()
{
    return accountNumber;
}

public void setAccountNumber(int accountNumber)
{
    this.accountNumber = accountNumber;
}

public String getAccountType()
{
    return accountType;
}

public void setAccountType(String accountType)
{
    this.accountType = accountType;
}

public double getMinSavings()
{
    return minSavings;
}

public void setMinSavings(double minSavings)
{
    this.minSavings = minSavings;
}

public double getMinChecking()
{
    return minChecking;
}

public void setMinChecking(double minChecking)
{
    this.minChecking = minChecking;
}

public double getCurrentBalance()
{
    return currentBalance;
}

public void setCurrentBalance(double currentBalance)
{
    this.currentBalance = currentBalance;
}


public void calculateNewBalance()
{
    if (accountType.equals("S") || accountType.equals("s"))
    {
        accountType = "Savings";
        calculateSavingsBalance();

    } else if (accountType.equals("C") || accountType.equals("c"))
    {
        accountType = "Checking";
        calculateCheckingBalance();
    }


}

private void calculateSavingsBalance()
{

    if (currentBalance >= minSavings)
    {
        double newBalance = currentBalance + (currentBalance * .04 / 12);

        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
    }
    else if(currentBalance < minSavings)
    {
        isServiceCharge();
    }

}


private void calculateCheckingBalance()
{
    if (currentBalance > 6000)
    {
        double newBalance = currentBalance + (currentBalance * .03 / 12);
        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
    }
    else if (currentBalance >= minChecking)
    {
        double newBalance = currentBalance + (currentBalance * .05 / 12);
        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);

    }
    else if(currentBalance < minChecking)
    {
        isServiceCharge();
    }


}

public void isServiceCharge()
{
    if(accountType.equals("s") || accountType.equals("S"))
    {
        double newBalance = currentBalance - 10.0;
        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
    }
    else if(accountType.equals("c") || accountType.equals("C"))
    {
        double newBalance = currentBalance - 25.0;
        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
    }

}
}

Aucun commentaire:

Enregistrer un commentaire