【发布时间】:2016-06-29 17:39:29
【问题描述】:
在以下代码中,使用 main 方法在每次交易后打印帐号和更新的余额,或者直到输入 Q。
在方法Update balance which中,给定账户余额,交易类型(D =存款,W =提款,Q =退出)和交易金额,计算机并在存款后返回新的账户余额或提取给定金额号码。
但是现在我遇到了问题,不知道如何修复我生成的这段代码
import java.util.Scanner ;
public class CustomerAccount
{
public static void main( String[] args )
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter the account number: ") ;
String accountNumber = in.nextLine() ;
System.out.print("Please enter the initial balance: ") ;
int startingBal = in.nextInt() ;
int updatedBal = startingBal ;
System.out.print("Please enter the transaction type /(D to deposit, W to withdraw, Q to quit: ") ;
String type = in.nextLine() ;
while(!"Q".equals(type))
{
System.out.print("Please enter the amount to be deposited or withdrawn: ") ;
int adjustment = in.nextInt();
if(type.equals("D"))
{
updatedBal = updatedBalance(depositAmt);
}
else
updatedBal = updatedBalance(withdrawAmt);
}
System.out.println("Account Number: " + accountNumber + " UpdatedBalance: $" + updatedBal) ;
}
}
public static int updatedBalance(int amount)
{
amount = amount + adjustment ;
return amount;
}
}
给出以下输出:
[File: /CustomerAccount.java Line: 28, Column: 19] class, interface, or enum expected
[File: /CustomerAccount.java Line: 31, Column: 9] class, interface, or enum expected
[File: /CustomerAccount.java Line: 32, Column: 5] class, interface, or enum expected
【问题讨论】:
-
使用
do-while循环,先获取输入工作,然后检查循环条件。 -
在你修复大括号之后,你会遇到一个问题,可以通过查看这里的解决方案来解决 ==> stackoverflow.com/questions/13102045/…
-
是的,现在它找不到变量 depositAmt、withdrawAmt 和adjustment
-
@timNorth - 老实说,我认为您应该考虑学习基本教程或其他内容?
-
是的,我认为这是个好主意