问题描述
这里有些困惑。我设置的方式在被调用时,应该循环遍历所填充数组的每个元素,并检查该元素的int accNum是否等于传递的int accNum,如果是,则输出帐户摘要。
也许我的逻辑是错误的,但在我看来应该可行:
public void accountInfo(int accNum)
{
for (int i = 0; i < numAccounts; i++)
{
if (accNum == accounts[i].getAccNum())
{
accounts[i].summary();
}
else
{
System.out.println("No such account on record.");
}
}
}
帐户类别:
public class Account
{
private String ssn;
private int accNum,accType;
private double balance;
private Customer accountHolder;
public Account(Customer accountHolder,String ssn,int accNum,int accType,double balance)
{
this.accountHolder = accountHolder;
this.ssn = ssn;
this.accNum = accNum;
this.accType = accType;
this.balance = balance;
}
public String summary()
{
String fullType;
switch (accType)
{
case 1:
fullType = "Checking";
break;
case 2:
fullType = "Savings";
break;
default:
fullType = "Other";
}
return String.format(("\t- Number: %d\n\t- %s\n\t- Balance: $%.2f\n\t- Customer: %s"),accNum,fullType,balance,accountHolder.getName());
}
public double getBalance()
{
return balance;
}
public int getAccNum()
{
return accNum;
}
public void deposit(double balance)
{
this.balance += balance;
}
public void withdraw(double balance)
{
this.balance -= balance;
}
}
/*Note that an Account object can have only one Customer.
*/
我的输出:
========== READ DATA ==========
========== DONE ==========
========== BANK INFORMATION ==========
Bank Name: CSUMB
Number of Customers: 4
Tom Smith: 777-77-7777
Alice Smith: 888-88-8888
Joe Otter: 999-99-9999
Monica Smith: 123-45-7777
Number of Accounts: 5
1000: $10.00
2000: $50.25
3000: $100.00
5000: $100.25
6000: $500.25
Bank Total Balance: $760.75
========== ACCOUNT INFORMATION ==========
No such account on record.
No such account on record.
No such account on record.
No such account on record.
应该在什么时候
========== ACCOUNT INFORMATION ==========
- Number: 1000
- Checking
- Balance: $10.00
- Customer: Tom Smith
========== ACCOUNT INFORMATION ==========
- Number: 1000
- Checking
- Balance: $160.25
- Customer: Tom Smith
========== ACCOUNT INFORMATION ==========
- Number: 1000
- Checking
- Balance: $60.25
- Customer: Tom Smith
========== ACCOUNT CLOSE ==========
Account closed.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)