我在如何返回主菜单时遇到问题。存入银行后,我想再次向用户显示主菜单,但我不知道这里有什么问题。为了查明我的确切问题.. 存入银行后,当我输入“Y”并单击“确定”按钮时,主菜单应该再次出现,但它没有出现。
这是我的程序。
基类:
import java.io.*;
import java.util.*;
public class BankAccount
{
public BankAccount(double b, String n)
{
double balance = b;
String name = n;
}
public void deposit(double d)
{
balance += d;
}
public void withdraw(double w)
{
balance -= w;
}
public String nickname()
{
System.out.print("Enter a new name: ");
Scanner kbIn = new Scanner(System.in);
String n = kbIn.nextLine();
return n;
}
double balance;
String name;
}
测试类:
import java.awt.Component;
import java.io.*;
import javax.swing.JOptionPane;
import java.util.*;
public class Tester {
private static String name;
private static double bal;
private static double withdraw;
public static void main(String args[]) {
Scanner kbInLine = new Scanner(System. in );
Scanner kbIn = new Scanner(System. in );
name = JOptionPane.showInputDialog(null, "Enter your name: ");
String num;
int pin;
num = JOptionPane.showInputDialog("Enter your pin number: ");
pin = Integer.parseInt(num);
JOptionPane.showMessageDialog(null, "Login Success\n" + "Name : " + name + "\n" + "Pin Number : " + pin);
BankAccount myAccount = new BankAccount(withdraw, name);
String[] buttons = {
"Deposit", "Withdraw", "Print Balance", "Exit"
};
int rc = JOptionPane.showOptionDialog(null,
"What would you like to do?",
"Confirmation",
JOptionPane.INFORMATION_MESSAGE,
0,
null,
buttons,
buttons[2]);
if (rc == 0) {
int deposit;
String dep = JOptionPane.showInputDialog("How much would you like to deposit?\n\t$ ");
deposit = Integer.parseInt(num);
JOptionPane.showMessageDialog(null, "You have deposited $" + dep + " into the account of " + name);
String proceeds = "y";
while (proceeds.equalsIgnoreCase("y"))
do {
proceeds = JOptionPane.showInputDialog(null, "\nWould you like to do another transaction? (Y/N)");
} while (proceeds.equalsIgnoreCase("Y"));
System.exit(0);
}
if (rc == 1) {
double withdraw;
String with = JOptionPane.showInputDialog("How much would you like to withdraw?\n\t$");
withdraw = Integer.parseInt(num);
if (bal - withdraw > 0) {
myAccount.withdraw(withdraw);
JOptionPane.showMessageDialog(null, "You have withdrawn $" + withdraw + " from the account of " + name + ". The new balance is: " + myAccount.balance);
} else {
JOptionPane.showMessageDialog(null, "Sorry, you have insufficient funds for this operation. Your existing balance is $" + myAccount.balance);
}
String proceeds = "y";
while (proceeds.equalsIgnoreCase("y"))
do {
proceeds = JOptionPane.showInputDialog(null, "\nWould you like to do another transaction? (Y/N)");
} while (proceeds.equalsIgnoreCase("Y"));
System.exit(0);
}
if (rc == 2) {
JOptionPane.showMessageDialog(null, "The balance in the account of " + name + " with the pin number " + num + " is $" + bal);
String proceeds = "y";
while (proceeds.equalsIgnoreCase("y"))
do {
proceeds = JOptionPane.showInputDialog(null, "\nWould you like to do another transaction? (Y/N)");
} while (proceeds.equalsIgnoreCase("Y"));
System.exit(0);
}
if (rc == -1) {
System.exit(0);
} else {
JOptionPane.showMessageDialog(null, "\nThank you. Have a good day!");
System.exit(0);
}
}
}