Need help changing these methods according to this public TransactionResult crea
ID: 643444 • Letter: N
Question
Need help changing these methods according to this
public TransactionResult createAccount(){
if(accounts[0] == null){
accounts[0] = new Account();
return new TransactionResult(true, "Account at index 0 created");
}
else if(accounts[1] == null){
accounts[1] = new Account();
return new TransactionResult(true, "Account at index 1 created");
}
else{
return new TransactionResult(false,
"Account not created, account limit reached (2 accounts already exist)");
}
}
public String details(){
StringBuilder builder = new StringBuilder();
builder.append("Customer:").append(firstName).append(" ")
.append(lastName).append(System.lineSeparator());
if(hasNoAccounts()){
builder.append("Customer has no accounts");
}
else{
for(int index = 0; index < accounts.length; index++){
if(accounts[index] != null){
builder.append(accounts[index].details());
if(index != accounts.length - 1){
builder.append(System.lineSeparator());
}
}
}
}
return builder.toString();
}
Explanation / Answer
class abc
{
public TransactionResult createAccount(String ac)
{
if(accounts[0] == null)
{
accounts[0] = new Account();
return new TransactionResult(true, "Account at index 0 created",);
}
else if(accounts[1] == null )
{
if (ac=="savingaccount" || ac=="chequingaccount")
{
accty[0]=ac;
accounts[1] = new Account();
return new TransactionResult(true,"Account at index 1 created"+accty[0]);
}
else{
return new TransactionResult(false,
"Account not created, account limit reached (2 accounts already exist");
}
}}
public String toString(){
// StringBuilder builder = new StringBuilder();
// builder.append("Customer:").append(firstName).append(" ")
.append(lastName).append(System.lineSeparator());
if(hasNoAccounts()){
builder.append("Customer has no accounts");
}
else{
for(int index = 0; index < accounts.length; index++){
if(accounts[index] != null){
builder.append(accounts[index].details());
if(index != accounts.length - 1){
builder.append(System.lineSeparator());
}
}
}
}
return builder.toString();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.