【发布时间】:2018-09-26 16:46:42
【问题描述】:
我几乎完成了这个银行账户程序。我调用了calculateSavings() 方法或calculateCheckings() 方法。如果currentBalance小于要求的minSavings或minChecking,我有else语句调用isServiceCharge()方法扣费。该程序没有给我错误,但如果用户输入的currentBalance 小于minChecking 或minSavings 所需的数量,则JOptionPane 不会显示输出。输入仍然有效,但没有弹出输出。其他一切都很好,例如增加利息,但在服务费中扣除费用则不行。我怎样才能解决这个问题?
主类
package com.company;
import javax.swing.*;
public class Main
{
public static void main(String[] args)
{
{
BankAccount myBank = new BankAccount();
myBank.calculateNewBalance();
}
}
}
银行账户类
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);
}
}
}
【问题讨论】:
-
你应该学习如何使用调试器...
标签: java if-statement methods method-call