Question: Help with return an arraylist like the sample below, show savings account for a customer. please see my code below. Examples of what what is

Help with return an arraylist like the sample below, show savings account for a customer.

please see my code below.

Examples of what what is returned should look like: [8505121231 Arne Nilson, 1004 SEK 0.00 Savings account 1.2%, 1005 SEK 0.00 Savings account 1.2%]

Please answer with the complemented cod inserted in bold in the below code. Thanks!

I have this switch/case below that shall evoke and print out the arraylist showing the account for a customer.

case 4:

{

System.out.print(\"Enter ssn: \");

ssn = sc.nextBigInteger().toString();

System.out.print(\"SSN: \"+ssn+\" \");

List customers = Bank.getCustomers();

for(Customer c:customers)

{

if(Objects.equals(c.getSSN(), ssn))

{

c.displayAccount();

}

}

}

And this customer class below

import java.util.ArrayList;

public class Customer

{

ArrayList accounts = new ArrayList<>();

int numberOfAccount;

//long ssn;

private final String ssn;

private String name;

public Customer(String ssn, String name)

{

numberOfAccount =0;

this.ssn = ssn;

this.name = name;

}

public String toString() {

return ssn+ \" \"+name;

}

public String getSSN() { return ssn; }

public String getName() {

return name;

}

public void setName(String n) {

this.name = n;

}

public ArrayList getAccounts() {

return accounts;

}

public void createAccount(float rate, float amount) {

SavingsAccount account = new SavingsAccount(rate, amount, ssn);

accounts.add(account);

numberOfAccount += 1;

}

public void displayAccount()

{

for (SavingsAccount account: accounts)

{

account.print(this.getName());

}

}

}

System.out.println(\"Account closed\"); System.out.println(\"Account number: \" + account Number); System.out.println(\"Account holder Name: \"+name); System.out.println(\"Account holder SSN: \"+Ssn); System.out.println(\"Balance: \" + balance); System.out.println(\"Account type: \" +

customers - Bank.get\" v:shapes=\"Picture_x0020_56\">

System.out.println(\"With interest 1,2 %:\"); System.out.println(\"Interest amount: \" + 0.012f * balance); } public void print(String name) { System.out.println(\"Account number: + account Number); System.out.println(\"Account holder name: + name); System.out.println(\"Balance: \" + balance); System.out.println(\"Account type: \"+accountType); System.out.println(\"Interest rate: \"+rate); } public int getAccount Number() { return account Number; } + public void deposit(float amount) { balance += amount; } public void withdraw(float amount) { if (amount > balance) { System.out.println(\" Insufficient balance!\"); return; } balance -

accountType); System.out.println(\"With interest 1,2 %:\"); System.out.println(\"Interest amount: \" + 0.012f * balance); } public void print(String name) { System.out.println(\"Account number: + account Number); System.out.println(\"Account holder name: + name); System.out.println(\"Balance: \" + balance); System.out.println(\"Account type: \"+accountType); System.out.println(\"Interest rate: \"+rate); } public int getAccount Number() { return account

new Scanner(System.in); BankLogic Bank = new BankLogic(); System.out.println(\" Welcome to the Bank\"); System.out.println(\"***** *\"); boolean doneWithBanking = false; while( !

doneWithBanking) { System.out.println(\" Add a new Customer 1\"); System.out.println(\"Delete a customer 2\"); System.out.println(\"Create an account for existing customer 3\");

System.out.println(\"See information for a customer 4\"); System.out.println(\"Deposit 5\"); System.out.println(\"Withdraw 6\"); System.out.println(\"Edit a customer name 7\"); System.out.println(\"Show all customer 8\"); System.out.println(\"Quit 0\"); System.out.print(\" Enter your choice: \"); int choice = sc.nextInt(); String ssn; switch (choice) { case 1: { while(true) {

accounts = new ArrayList<>(); int numberOfAccou\" v:shapes=\"Picture_x0020_61\">

System.out.print(\"Enter customer unique ssn: \"); ssn = sc.nextBigInteger().toString(); if(Bank.checkSsn(ssn)) { break; } else { System.out.println(\"Already exist, enter a unique ssn.\"); } } System.out.print(\"Enter customer name: \"); sc.nextLine(); String name = sc.nextLine(); Customer customer = new CustomerBuilder().setSsn (ssn).setName (name).createCustomer(); Bank.addCustomer(customer); System.out.println(\" Customer added successfully with uniquely

getCustomers() { return customers; } public void setCustomers(List

ssn: \" + customer.getSSN(); } break; case 2: { System.out.print(\"Enter ssn: \"); ssn = sc.nextBigInteger().toString(); Bank.removeCustomer(ssn); } break; case 3: { System.out.print(\"Enter customer ssn: \"); ssn = sc.nextBigInteger().toString(); List customers - Bank.getCustomers(); for (Customer c: customers) { if (Objects.equals(c.getSSN(), ssn)) { System.out.print(\"Amount: \"); float amount = sc.nextFloat(); if (amount != 0) { c.createAccount( rate: 1.2f, amount); System.out.println(\" Account added for customer with ssn: } else { System.out.println(\" Amount must be over 0 \"); } + ssn); } } } break; case 4: { System.out.println(Bank.getCustomers()); L*System.out.print(\"Enter ssn: \"); ssn =

sc.nextBigInteger().toString(); System.out.print(\"SSN: \"+s4n+\" \"); List customers = Bank.getCustomers(); for(Customer c:customers) { if(Objects.equals(c.getSSN(), ssn)) { List accounts = c.getAccounts(); System.out.print(\" Enter account number to deposit: \"); int accno = sc.nextInt(); System.out.print(\"Enter deposited amount: \"); float amount = sc.nextFloat(); if (amount > 0) { for (SavingsAccount a: accounts) { if (a.getAccount Number()

accno) { a. deposit(amount); } } } else { System.out.println(\"Amount must be over 0.\"); } } } } break; case 6: { System.out.print(\"Enter ssn: \"); ssn = sc.nextBigInteger().toString(); System.out.print(\"SSN: \"+Ssn); List customers = Bank.getCustomers(); for(Customer c:customers) { if(objects.equals(c.getSSN(), ssn)) { List accounts = c.getAccounts(); System.out.print(\" Enter account number to withdraw: \"); int accno = sc.nextInt(); System.out.print(\"Enter withdraw amount: \"); float amou

Hade to provide pics, otherwise says text question will be to big in size.

Hi, ok. BankLogic class below, thanks

import java.util.ArrayList;

import java.util.List;

import java.util.Objects;

import java.util.stream.Collectors;

public class BankLogic

{

List customers;

int numberOfCustomers;

public String ssn;

public BankLogic()

{

numberOfCustomers = 0;

customers = new ArrayList<>();

}

public void addCustomer(Customer customer)

{

customers.add(customer);

numberOfCustomers +=1;

}

public void removeCustomer(String ssn)

{

this.ssn = ssn;

for (int i = 0; i < customers.size();=\"\">

{

if (Objects.equals(customers.get(i).getSSN(), ssn))

{

List accounts = customers.get(i).getAccounts();

for (SavingsAccount account : accounts)

{

account.close(customers.get(i).getName());

}

customers.remove(customers.get(i));

}

}

numberOfCustomers -=1;

}

public List getCustomers()

{

return customers;

}

public void setCustomers(List newCustomers)

{

customers = newCustomers;

}

public boolean checkSsn(String ssn){

for(Customer c : customers) {

if(Objects.equals(c.getSSN(), ssn)) {

return false;

}

}

return true;

}

public ArrayList getAllCustomers() {

if (customers == null || customers.isEmpty()) {

return new ArrayList<>();

}

return (ArrayList) customers.stream().map(Objects::toString).collect(Collectors.toList());

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!