CPSC 215L Lab 5, 9/30/99; Due 10/7/99 This lab continues to address linked lists, execept this time we'll use lists of bank accounts instead of just integers. The bank account class is defined as follows: class account { public String owner; // name of owner private double balance; // floating point value of balance account(String s, double b) { owner = s; balance = b; } public void deposit(double amt) { balance = balance + amt; } public void withdraw(double amt) { if (balance >= amt) balance = balance - amt; else System.out.println("transaction refused"); } public double checkbalance() { return balance; } } // end of class account The account objects will then be put into a list class as before: class acell // the "account cell" class { acount head; // so what will "front.head.deposit(30)" do? acell tail; // other accounts. acell(account h, acell t) { head = h; tail = t; } } Your "public" class should store management information concerning the account: public class bank // wrapper class with "front", also used for demo with main { acell front; // convenient pointer to front of the list /* code for your methods goes here */ public static void main(String[] args) { bank mybank = new bank(); // you need to create a bank first bank yourbank = new bank(); account myaccount = new account("the professor",200.0); account youraccount = newaccount("a student", 300.0); mybank.front = new acell(myaccount,null); // adds myaccount to mybank. // adds youraccount in front of myaccount, in the same "bank" mybank.front = new acell(youraccount,mybank.front); // create additional test data and test runs, and demonstrate your methods. } // end main } // end of public class bank ---------------------------------------------------------------------------- You are to do the following, which may also involve transporting the methods for integer lists to account lists: 1. Define a method that will print out the name of the owner and the balance of every account in the list. Make sure the formatting is clear. 2. Define a method that, given a name, will look through the list of accounts for an "owner" of that name, and return the account (not just the balance: "public account lookup(String name)" ). This implies that you must have it return null if no such account exists. For this problem you don't have to worry about different accounts with the same owner - just return the first one you find. 3. Write a account creation method so that a new account is inserted into the list in *alphabetical order* (with respect to the name of the owner). It should also print a message such as "account already exists. go to another bank" if there's already an account for that owner. Java has the ability to compare strings in the alphabetical ordering built-in: if A and B are strings then 'A.compareTo(B)' will return 0 if they are equal, a negative number if A comes before B alphabetically, and a positive number if A comes after B alphabetically. This method requires only slight modifications to the "insertAt" method. sketch out what should happen on paper first before coding. 4. Write a "close account" method that, given a name as argument, will find and delete the account with the given name from the list of accounts. For this you need to understand how the "insertat" method was created, so you can re-link the pointers properly. You should assume that the list is sorted by name, so you do NOT have to go all the way through the list if the account you're closing doesn't exist. For this problem you can also assume that there are no accounts with duplicate names. 5. Write a method that will go through a "bank" list of accounts and return a list containing all accounts in the bank with balances below $50.0. That is, the header for the method (inside the bank class) should be "public acell belowlimit()". Hint: use an accumulator. Remember, in all these methods, you must also take care of special circumstances such as when the list is null. ---------------- Lab 5 Demonstration Requirements: As part of our grading of your lab 5 solutions, you will be required to provided demonstrations of your programs operating in the following special circumstances, in addition to normal situations: 1. Your "find account" method in a situation where: a. the list of accounts is null. b. no account of that name exists in the list. 2. Your "close account" method in a situation where: a. the account you're trying to close doesn't exist b. the account being deleted is at the front of the list 3. Your modified "create account" method in a situation where: a. the list is null b. an account of the same name already exists c. the new account should be inserted at the front of the list