问题描述
下午好,
我正在制作一个银行应用程序。 用户可以选择将钱从一个帐户转移到另一个帐户,这是菜单中的选项 5。 我希望用户选择他想要转账的银行账户和金额。 这是选项 5 的代码:
} else if (inputin == 5) {
System.out.println("Choose a bank account to transfer to: ");
for (int y = 0; y < bankAccountsList.length; y++) {
System.out.printf("%d %s%n",y + 1,bankAccountsList[y]);
}
Scanner transferbankChoice = new Scanner(system.in);
int inputBankChoiceTransfer = transferbankChoice.nextInt();
System.out.println(bankAccountService.transfer("" currentaccount comes here "","" account chosen comes here "",300));
我打算使用“当前帐户”,这是用户可以选择使用的帐户,但我也无法解决此问题。 这个想法很简单,当菜单弹出时,用户可以“选择银行账户”,一旦我选择的账户可以使用菜单中的所有其他选项。
package BankProject;
import java.awt.desktop.SystemEventListener;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
BankAccountService bankAccountService = new BankAccountService();
Person person = new Person();
BankAccount account0 = new BankAccount();
account0.accountNumber = "BE42 2556 2556 1442";
account0.balance = 1000;
account0.lowerLimit = 0;
account0.currency = "EUR";
person = new Person();
person.firstName = "Nani";
person.familyName = "Poonani";
person.address = "grove Str.";
account0.person = person;
bankAccountService.addBankAccount(account0);
BankAccount account1 = new BankAccount();
account1.accountNumber = "BE42 2556 2556 4200";
account1.balance = 500;
account1.lowerLimit = 0;
account1.currency = "EUR";
person = new Person();
person.firstName = "Carl";
person.familyName = "Jackson";
person.address = "grove Str. 420";
account1.person = person;
bankAccountService.addBankAccount(account1);
BankAccount account2 = new BankAccount();
account2.accountNumber = "BE42 2556 2556 7577";
account2.balance = 100;
account2.lowerLimit = 0;
account2.currency = "EUR";
person = new Person();
person.firstName = "Big";
person.familyName = "Smoke";
person.address = "Ballas Str. 777";
account2.person = person;
bankAccountService.addBankAccount(account2);
// System.out.println(bankAccountService.deposit(account1,100));
// System.out.println(bankAccountService.deposit(account2,300));
// System.out.println(bankAccountService.deposit(account0,600));
// System.out.println(bankAccountService.withdraw(account1,25));
//System.out.println(bankAccountService.withdraw(account2,50));
// System.out.println(bankAccountService.withdraw(account0,100));
//System.out.println(bankAccountService.transfer(account1,account2,100));
// System.out.println(bankAccountService.transfer(account2,account0,300));
//System.out.println(bankAccountService.transfer(account0,account1,600));
//System.out.println(bankAccountService.getAccount("BE42 2556 2556 7577"));
String bankAccountsstring = "BE42 2556 2556 7577,BE42 2556 2556 4200,BE42 2556 2556 1442";
String[] bankAccountsList = bankAccountsstring.split(",");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.println("! Welcome To San Andreas Bank !");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.println("--------------------------------------------------");
System.out.println("Current account: ");
System.out.println("--------------------------------------------------");
System.out.println("Enter one of the following numbers to select: ");
System.out.println(" ");
System.out.println("1.Select bank account ");
System.out.println("2.Check account balance ");
System.out.println("3.Deposit ");
System.out.println("4.Withdraw money ");
System.out.println("5.Transfer money ");
System.out.println("6.Exit ");
Scanner inputin1 = new Scanner(system.in);
int inputin = inputin1.nextInt();
if (inputin <= 0 || inputin > 6) {
System.out.println("Please try again,choose a number between 1 and 6");
} else if (inputin == 1) {
System.out.println("Choose a bank account: ");
for (int y = 0; y < bankAccountsList.length; y++) {
System.out.printf("%d %s%n",bankAccountsList[y]);
}
Scanner bankChoice = new Scanner(system.in);
int inputBankChoice = bankChoice.nextInt();
if (inputBankChoice == 1) {
System.out.println("Your current account is Now: " + bankAccountService.getAccount("BE42 2556 2556 7577"));
} else if (inputBankChoice == 2) {
System.out.println("Your current account is Now: " + bankAccountService.getAccount("BE42 2556 2556 4200"));
} else if (inputBankChoice == 3) {
System.out.println("Your current account is Now: " + bankAccountService.getAccount("BE42 2556 2556 1442"));
}
} else if (inputin == 2) {
System.out.println(bankAccountService.getAccountBalance(account0));
} else if (inputin == 3) {
System.out.println(bankAccountService.deposit(account1,100));
} else if (inputin == 4) {
System.out.println(bankAccountService.withdraw(account0,100));
} else if (inputin == 5) {
System.out.println("Choose a bank account to transfer to: ");
for (int y = 0; y < bankAccountsList.length; y++) {
System.out.printf("%d %s%n",bankAccountsList[y]);
}
Scanner transferbankChoice = new Scanner(system.in);
int inputBankChoiceTransfer = transferbankChoice.nextInt();
System.out.println(bankAccountService.transfer("" currentaccount comes here "",300));
} else if (inputin == 6) {
}
}
}
欢迎所有建议我已经学习了 1 个月的 Java,这段代码可能有很多错误。
问候
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)