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

Due date: Thursday, April 8, when labs close.

    Honoring the API is an important part of software development. In cs110 that means (among other things) that when you write code that must interact with code you've been given, you may only change the files that you are asked to change. If you turnin too much you have not followed instructions. At best you will lose points for just turning in unnecessary code. At worst, your code won't run when we test it with our classes.

    Testing is an important part of the software development process. So everything you write must be tested and you must write about your testing in your memo, even if the exercise does not explicitly ask for it.

  1. JOI Exercise 6-2 (Exploring Juno). You can do this exercise without copying and compiling code. Just download file juno.jar and run Juno with the command
    	java -cp juno.jar Juno
    
    	From: Ethan Bolker 
    	Subject: Java 1.4 / Java 1.5 incompatibility
    	Date: Fri, 2 Apr 2004 19:57:16 -0500 (EST)
    
    	If you try
    
    		java -cp juno.jar Juno
    
    	with Java 1.5 and  the original jar file the link above
    	you get an error.
    
    	I have replaced that jar file with one that works both with 
    	Java 1.4 and Java 1.5.
    

  2. JOI Exercise 6-4. You will have to create the new class UserTable, modify Juno.java, and modify the source code in one other class.
    From: Ethan Bolker 
    Subject: what needs to be modified
    Date: Tue, 6 Apr 2004 13:34:59 -0400 (EDT)
    
    You don't in fact have to modify anything other than Juno.java to
    use the new UserTable class. But you may modify some other file if you
    decide to. Just be sure to turn it in.
    
    If you have rewritten User.java in order to add a toString() (for
    finger) then turnin that file.
    
    We will test your Juno with all the classes you turnin, using ours
    when you haven't given us one. But you will lose points if you turnin
    files you have not changed, or if your design calls for changes in
    many places when just a few would suffice.
    
     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: Homework8:6-4
     > Date: Tue, 6 Apr 2004 09:07:31 -0700 (PDT)
     > 
     > Dear Professor,
     > 
     > As specified in No.2 question, we are supposed to modify
     > UserTable.java, Juno.java and one more source file. But I have a
     > question:
     > 
     > I have done with UserTable and Juno, and I put them in test with
     > other classes. My modification works without changing one more
     > source file.
     > 
     > I don't know if I have to change the unknown source file? 
    
    
    

  3. Explain how the stripComments method in class Shell does its job by walking through the code as it processes the newfile command in the example that follows. You'll have to look up some things in the String API to answer this question.
    	Welcome to mars running Juno version 6
    	help, register, <username>, exit
    
    	Juno login: register eb Ethan Bolker
    	Juno login: eb
    	mars> newfile memo.txt my memo for hw8 # always start this first
    	mars> type memo.txt
    	my memo for hw8
    	mars> logout
    	goodbye
    	Juno login: exit
    

    Your solution (in memo.txt) should show the state of the various Strings and StringTokenizers at each step.

  4. Explain why "logout" does not appear in the list when you ask for help at the Juno shell prompt. (You will have to find the right place in the code to answer this question.)

  5. JOI Exercise 6-9 (alias). Your answer should be in file AliasCommand.java.
    From: Ethan Bolker 
    Subject: hw8
    Date: Sat, 3 Apr 2004 07:45:02 -0500 (EST)
    
    Excellent questions!
    
     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: hw8
     > Date: Sat, 3 Apr 2004 01:32:22 -0800 (PST)
     > 
     > hello Prof. Bolker,
    
     >  I have got a question about the Ex. 6-9 (alias), can we modify the
     > declaration of any method in ShellCommandTable from private to
     > public, for ex. if I want to change the access modifier of install
     > method to public, is it allowed.  
    
    In general, a solution that does not change an API is usually better
    than one that does. But if you can't solve a problem without a change,
    or if the solution without the change is really long and ugly, then
    it's better to change the API - as long as you discuss the change with
    the other programmers on your team. In thiscase that means writing
    about your design decision in your memo.
    
     > Moreover, I wanted to know whether the alias for the command
     > created will be valid through out the Juno session in which it is
     > created, or only for the user who creates it.
    
    Throughout the session.
    
    
    From: Ethan Bolker 
    Subject: alias in Juno
    Date: Sun, 4 Apr 2004 08:43:07 -0400 (EDT)
    
    Yes
    
     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: hw8
     > Date: Sun, 04 Apr 2004 03:20:05 -0500
     > 
     > Hi, Prof. Bolker
     > 
     > I have a question about AliasCommand.java.
     > After users create a newname for an existing command, will the old name 
     > still work as before?
    
    
    

  6. JOI Exercise 6-19 (finger). Use the version of Juno you wrote for problem 2.

  7. Optional. Modify Shell.java so that when the comment character is escaped with a backslash it does not start a comment, as in this example:
    	Welcome to mars running Juno version 6
    	help, register, <username>, exit
    
    	Juno login: register eb Ethan Bolker
    	Juno login: eb
    	mars> newfile comment.txt '\#' is Juno's comment character. # OK?
    	mars> type comment.txt
    	'#' is Juno's comment character. 
    
    Anywhere but before a '#' the '\' is an ordinary character.

  8. Optional. Rewrite Juno version 6 so that it uses Java 1.5 collections. Every unchanged line of code should have the same line number in its file after you have made the necessary changes. You should probably be able to do this using extra blank lines judiciously, since the iteration idiom in Java 1.5 uses fewer lines than its 1.4 counterpart.

    A good way to start is to compile the existing code with the Java 1.5 compiler and the -source option to see where warnings occur.

    Prof. Campbell and I will consider using the best of the submissions to start the process of converting all later releases (in chapters 7, 9 and 10).