This is the second exam I gave the last time I taught cs110. The corresponding exam this Spring will have a similar flavor, but will differ in detail. In particular, it will cover error handling and the call stack as well as collections and inheritance. Those are the three main topics covered since the last exam - Chapters 4, 5 and 7 in the text.

CS 110 Fundamentals of Computing - Hour Exam 2
Professor Bolker
November 20, 2001
Closed book and notes


login name ______________________________Name ________________________________

This space reserved for the grader

	1	2	3	4	5	6	 total
	  /15	  /10	  /15	  /15	  /25	  /20	    /100

Some of the questions call for discussions (like your memos). None of the answers should be long. One or two accurate sentences will usually do the job, if you know what you want to say. Be sure to read the question before you answer it.

If you need more space than I have allowed for an answer, turn the paper over and use the other side. Indicate when you have done that.

  1. (15) Here is line 27 in WordList.java (the full text is appended).
    	Iterator i = myWords.keySet().iterator();
    

    1. (3) How many tokens are there on that line?

    2. (4) Identify the tokens that refer to objects, and give the type of the object referred to in each case.

    3. (4) In what class would you expect to find method iterator declared?

    4. (4) Write the declaration header for the iterator method.





  2. (10) Lines 19 and 27 each contain a declaration for variable named "i ".

    1. (5) What is the scope of each of those variables?
    2. (5) Why is i a good name in each case?




  3. (15) What will be printed in response to following command?
    	% java WordList zero one two three
    








  4. (15) "Polymorphism makes it possible to design software that works with collections of objects of similar but not identical types."

    Discuss this assertion, using at least two examples from the Bank, Shapes and Juno packages. Be sure your discussion makes clear your understanding of polymorphism, inheritance and collections.






















  5. (25) Here is how Juno's version of the Unix finger command behaves:
    	% java Juno
    	Welcome to notMars running Juno version 6
    	help, register, , exit
    
    	Juno login: register jill Jill Q. Public
    	Juno login: jill
    	notMars> finger jill
    	jill	Jill Q. Public
    	notMars> finger root
    	root	Rick Martin
    	notMars> logout
    	goodbye
    	Juno login: exit
    
    At the end of this exam you will find a stub version of file FingerCommand.java . Complete it.

    Since you don't have access to the rest of Juno on this exam, here is some of the API (generated with grep) that you may find useful:

       class   	  method
        Juno    public User lookupUser( String username )  
    
       Shell    public User getUser()  
       Shell    public Directory getDot()     
       Shell    public Terminal getConsole() 
       Shell    public Juno getSystem() 
    
        User    public String getName()    
        User    public String getRealName()
    
    

  6. (20) Suppose Juno is running and these commands have been typed so far:
    	% java Juno
    	Juno login: register jack John Q. Public
    	Juno login: jack	
    	notMars:/users/jack> newfile .cshrc this is my .cshrc file
    	notMars:/users/jack> newfile memo.txt Here is my memo
    

    1. Draw a picture of the complete JFile hierarchy at this moment.
      Hint: your picture should show three directories.












    2. Draw a box-and-arrow picture of the JFiles that have been created. Your picture should show the jfiles field of each Directory and the parent field of each JFile . You need not show owners or dates or the contents of text files.