Guest User

Untitled

a guest
Jan 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package com.knowledgeblackbelt.students.ideynega.exercises;
  2.  
  3. import java.util.List;
  4. import java.util.LinkedList;
  5.  
  6. public class Exercise454 {
  7.  
  8.     public static void main(String[] args) {
  9.         List<BankAccount> bankAccountList = getBankAccountList();
  10.         List<Customer> customerList = extractCustomerListFromBankAccountList(bankAccountList);
  11.         provideClientService(customerList);
  12.     }
  13.    
  14.     public static List<BankAccount> getBankAccountList() {
  15.         List<BankAccount> bankAccountList = new LinkedList<BankAccount>();
  16.         bankAccountList.add(new BankAccount("1", 25000.0, new Customer("Robert", "Johnson")));
  17.         bankAccountList.add(new BankAccount("2", 150.0, new Customer("John", "Robertson")));
  18.         return bankAccountList;
  19.     }
  20.    
  21.     public static List<Customer> extractCustomerListFromBankAccountList(List<BankAccount> bankAccountList) {
  22.         List<Customer> customerList = new LinkedList<Customer>();
  23.         for(BankAccount ba: bankAccountList) {
  24.             customerList.add(ba.customer);
  25.         }
  26.         return customerList;
  27.     }
  28.    
  29.     public static void provideClientService(List<Customer> customerList) {
  30.         for(Customer currentCustomer: customerList) {
  31.             System.out.println("Customer " + currentCustomer.firstName + " " + currentCustomer.lastName + " has been provided with customer service");
  32.         }
  33.     }
  34. }
  35.  
  36. class BankAccount {
  37.  
  38.     String number;
  39.    
  40.     double balance;
  41.    
  42.     Customer customer;
  43.    
  44.     BankAccount(String number, double balance, Customer customer) {
  45.         this.number = number;
  46.         this.balance = balance;
  47.         this.customer = customer;
  48.     }
  49. }
  50.  
  51. class Customer {
  52.  
  53.     String firstName;
  54.    
  55.     String lastName;
  56.    
  57.     Customer(String firstName, String lastName) {
  58.         this.firstName = firstName;
  59.         this.lastName = lastName;
  60.     }
  61. }
Add Comment
Please, Sign In to add comment