lundi 24 septembre 2018

How to properly use if else statements in getter and setter methods?

I am trying to create a bank account program where the user can enter either "s" or "S" account types for a Savings account. They can also enter "c" or "C" for a checking account. I'm having problems with getting the user input to run through getter/setter methods then returning in the output the String "Savings" or "Checking" depending on the input.

package com.company;
import javax.swing.*;
public class Main

`

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

        myBank.setAccountType(JOptionPane.showInputDialog("please enter an account type"));
        JOptionPane.showMessageDialog(null, "Account Number: " + "\nAccount Type: " + myBank.getAccountType() +"\nMinimum Balance: "+ "\nBalance Before Interest and Fees: " + "\n\nNew Balance:\n");


    }
}

}

package com.company;

public class BankAccount

{
    private int accountNumber;
    private String accountType;
    private double minSavings = 2500;
    private double minChecking = 1000;
    private double currentBalance;


    public BankAccount()
    {
    }

    public String getAccountType ()
    {
        return this.accountType;
    }

    public void setAccountType (String please_enter_an_account_type)
    {
        if (accountType == "S" || accountType == "s")
        {
            this.accountType = "Savings";
        }

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

    }
}

Aucun commentaire:

Enregistrer un commentaire