我的朋友创建了一个银行/ATM 交易程序。它允许用户存款、取款和查看余额。但问题是,它不允许用户选择他/她想要进行的交易,它总是要求用户先存款,然后才能提款或再次检查余额。所以我有了一个提供组合框的想法,但我的另一个问题是我不知道该怎么做,因为我只是 Java 编程的初学者。
import javax.swing.JOptionPane;
public class atm {
public static void main (String[] args){
while(true){
String intro = "Welcome to ATM Transactions";
JOptionPane.showMessageDialog(null,intro);
String number1 = JOptionPane.showInputDialog("Please enter the amount to deposit:");
String number2 = "The amount deposited is:" + number1;
JOptionPane.showMessageDialog(null,number2);
String number3 = JOptionPane.showInputDialog("Please enter the amount to withdraw:");
int number4 = (Integer.parseInt(number1)) - (Integer.parseInt(number3));
String answer = "The remaining balance is:" +number4;
JOptionPane.showMessageDialog(null,answer);
String[] choices = {"Yes", "No"};
int response = JOptionPane.showOptionDialog(null,"Do you want another
transactions?","Question",
JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,choices,"No");
if (response==1)
System.exit(0);
}
}
}
所以我的问题是,如何将它变成一个组合框,以便用户可以选择他/她想要执行的交易,并且用户可以在不经过第一步的情况下进行多次存款或取款?