Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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();
   }

Class Customer rename method details as to String and @Override make sure you also call to String on each account make changes to method create Account add parameter of Account Type inside the method, based on Account Type, create and assign reference to either a Saving Account or a Chequing Account into the array of Account references optionally return a message in the Transaction Result that indicates the account type created

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();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote