我目前正在尝试编写一种方法,该方法将首先要求存款、取款或退出。
然后询问帐户名称(这将通过名称从数组列表中获取帐户)
然后提示输入所选存款或取款的金额。
然后回到(存款,取款,退出)提示
我写的代码顺序错误。(它要求输入名称,然后是操作,然后是金额),我不知道如何将其更改为上面所需的顺序。
我也无法弄清楚如何让循环在输入 3 时退出。
我想我已经接近了……只是似乎无法从这里前进。(ps while true 循环只是我尝试找出其余部分时使用的临时循环)
public void banking()
{
while(true)
{
Scanner scan4 = new Scanner(System.in);
System.out.println("please enter the name for the account"); //takes the name of the account to select the correct object in arraylist
String accountName = scan4.nextLine();
for(Account y: accounts) //for all the objects in the arraylist...
{
while(accountName.equalsIgnoreCase(y.getName()))
{
Scanner scan3 = new Scanner(System.in);
System.out.println("1:Deposit 2:Withdraw 3:Quit");
int request = scan3.nextInt();
if(request == 1)
{
Scanner scan = new Scanner(System.in);
System.out.println("please make a deposit");
double newBalance = scan.nextDouble();
y.deposit(newBalance);
}
else if (request == 2)
{
Scanner scan2 = new Scanner(System.in);
System.out.println("please make a withdrawl");
double withdrawl = scan2.nextDouble();
if(withdrawl > y.getBalance())
{
System.out.println("Insufficient funds");
}
else
{
y.withdraw(withdrawl);
}
}
else if (request == 3)
{
break;
}
}
}
}
}
墨色风雨
相关分类