问题描述
下面的代码应该执行以下操作:
- 循环遍历一系列帐户,其中包括(AccountHolder(由名称,地址和ssn组成),ssn,4位数字的帐号,一位数字的帐户类型(等同于支票或储蓄) ),以及帐户中的余额)
- 如果找到一个SSN和帐号相同的帐户,则假定他们拥有该帐户,存储该帐户持有人的姓名以供以后使用,然后运行测试:
- 继续循环浏览
- 如果它再次找到同一位客户,请检查他们是否具有其他帐户类型,如果是,则仅基于只能进行1次支票和1次储蓄的方式拒绝创建新帐户
- 如果他们已经拥有该类型的帐户,则基于只能一次最多进行1张支票或1次储蓄(即没有
- 否则,如果它检测到相同的SSN但帐号不同,则基于必须具有唯一的帐号来拒绝
- 如果所有检查都通过,则添加到帐户数组中。
public void newAccount(String ssn,int accNum,int accType,double initialBalance)
{
Boolean dupeAccType = false,sameAccNum = false,threeAccs = false;
String checkOrSave = null;
Customer tempCustomer = null;
for (int i = 0; i < numAccounts; i++) //for all existing accounts
{
if (accounts[i] != null)
{
System.out.println(accounts[i].getCustomer().getSsn().equals(ssn));
System.out.println(ssn);
System.out.println(accounts[i].getAccNum());
System.out.println(accNum);
System.out.println("");
if (accounts[i].getCustomer().getSsn().equals(ssn) && //if same ssn
accounts[i].getAccNum() == accNum) //and same accNum (if we already have this customer)
{
tempCustomer = accounts[i].getCustomer();
System.out.println(accounts[i].getAccType());
System.out.println(accType);
for (int j = i; j < numAccounts; j++) //loop through the rest of accounts
{
if (accounts[j] != null)
{
if (accounts[j].getCustomer().getSsn().equals(ssn) && //if same customer again
accounts[j].getAccNum() == accNum)
{
if (accounts[j].getAccType() != accType) //if customer has other account
{
threeAccs = true;
break;
}
}
if (accounts[i].getAccType() == accType) //if already have that type of account
{
dupeAccType = true;
if (accType == 1)
{
checkOrSave = "checking";
}
else
{
checkOrSave = "savings";
}
break;
}
}
}
}
else if ((!accounts[i].getCustomer().getSsn().equals(ssn)) && //if same accNum
accounts[i].getAccNum() == accNum)
{
sameAccNum = true;
break;
}
}
}
if (dupeAccType)
{
System.out.println("Account creation Failed - " + tempCustomer.getName() + " (" + ssn + ") already has a " + checkOrSave + " account");
}
else if (sameAccNum)
{
System.out.println("Account creation Failed - Account " + accNum + " already exists");
}
else if (threeAccs)
{
System.out.println("Account creation Failed - can only have one checking and one savings account");
}
else
{
System.out.println("Account creation - Number: " + accNum + ",Customer: " + tempCustomer);
Account tempAccount = new Account(tempCustomer,ssn,accNum,accType,initialBalance);
accounts[numAccounts + 1] = tempAccount;
numAccounts++;
}
}
我的问题是,由于某种原因,在遍历时,似乎跳过了值:
true
777-77-7777
1000
4000
false
777-77-7777
2000
4000
true
777-77-7777
3000
4000
false
777-77-7777
5000
4000
false
777-77-7777
6000
4000
Account creation - Number: 4000,Customer: null
System.out.println(accounts[i].getCustomer().getSsn().equals(ssn));
System.out.println(ssn);
System.out.println(accounts[i].getAccNum());
System.out.println(accNum);
请注意,它永远不会比4000和4000相提并论。我想知道为什么会这样。当然,这是我的逻辑,但我只是没有看到。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)