mardi 25 septembre 2018

How can I output either the required minimum savings or checking amount depending on user input?

If the user enters either "s" or "S" the JOptionPane should output "Minimum Balance: $2500." While an input of "c" or "C" should output similarly but $1000. How can I accomplish this? I have get and set methods for minSavings and minChecking but I only need to have one in the JOptionPane depending on user input for account type.

package com.company;

import javax.swing.*;

 public class Main
{


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

        JOptionPane.showMessageDialog(null, "Account Number: " + myBank.getAccountNumber() + "\nAccount Type: " + myBank.getAccountType() + "\nMinimum Balance: " + "\nBalance Before Interest and Fees: " + "\n\nNew Balance:\n");

    }

}



}



package com.company;

import javax.swing.*;

public class BankAccount

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


    public BankAccount()
    {
        accountNumber = Integer.parseInt(JOptionPane.showInputDialog("Please enter your account number"));
        accountType = JOptionPane.showInputDialog("Please enter your account type");


        if (accountType.equals("S") || accountType.equals("s"))
        {
            accountType = "Savings";

        }

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

        }


    }

    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;
    }
}

Aucun commentaire:

Enregistrer un commentaire