CS 110 Fundamentals of Computing
Homework Assignment 5
Bolker and Rodriguez
Spring 2004

Due date: Thursday, March 11, when labs close.

Hard copy of your box-and-arrow picture is due in class Wednesday/Thursday.

For more array practice, look at ArrayDemo2.java and ArrayDemo2.java with line numbers.

  1. JOI Exercises 4-7 (Selection sort) Practice with nested for loops (but not two dimensional arrays.)

  2. JOI Exercises 4-9 (Sort)

  3. JOI Exercises 4-20 (Bank)

  4. JOI Exercise 4-21 (BigBank). The input file bigbank.in and the corresponding correct output file bigbank.out referred to in the text can be downloaded from this page.

  5. JOI Exercise 4-26 (box-and-arrow)

  6. JOI Exercise 4-25 (Closing an account). (Just do this for the big bank you have written.)

    When you close an account in a big bank you need to decide what happens with the old account's number. If the report is

    	account   balance   transaction count
    	0	  $0		2
    	1	  $100		3
    	2	  $200		4
    	3	  $300		5
    
    and you close account 2 should you see
    	account   balance   transaction count
    	0	  $0		2
    	1	  $100		3
    	3	  $300		5
    
    or
    	account   balance   transaction count
    	0	  $0		2
    	1	  $100		3
    	2	  $300		5
    

    The first one would be better for a real bank. The owner of account 3 would be very surprised if her account number changed just because someone else closed an account.

    But the second one is easier to program using the ArrayList API, and we are just beginning programmers.

    You can do whichever you like for full credit on the homework - just make sure to discuss your choice in your memo.

    Closing an account should not count as a transaction, and the transaction count of the closed account should be subtracted from the Bank's transaction count (just as the balance is). (The answers might be different for a real bank, but we want to keep ours simple.)

    JOI says that the banker should be the one to close the account. But
    when I thought that through in response to Ricardo's question below I
    decided that it would be better if a customer closed his or her own
    account, after connecting to it in the usual way. So you should add a
    new customer transaction "close" to invoke the method
    
        public void close( BankAccount account )
    
    The customer should see the message
    
         "We will send you a check for [balance in account].
         "Thank you for banking with [name of Bank]. 
    
    
    Subject: closing an account
    Date: Tue, 9 Mar 2004 21:43:25 -0500 (EST)
    
     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: the method
     > Date: Tue, 09 Mar 2004 21:36:58 -0500
     > 
     > hello,
     > 
     > if a user closes the account, should the program automaticly
     > getting him out from the user account or after when the user types
     > "quit"?
    
    Good question. The only thing that makes sense is to say that close
    really means close and quit. If not, the user could try to see the
    balance in the account he just closed, or make a deposit there.
    
    

  7. Optional. JOI Exercise 4-10 (The sieve of Eratosthenes) If you do this problem be sure to discuss it in your memo so we grade it.

    Put a main method in your Eratosthenes class. main should expect a single integer on the command line, so

           > java Eratosthenes 10
    
    
    should produce exactly the output shown in the text as an example. In fact, you can use the code in the text in the body of main. Just replace the 10 there by the number from the command line. (Remember Integer.parseInt(), discussed in class.)