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

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

In this assignment you will finish the error handing in Juno. Start with the source code for juno 7.5, which will also serve as the solution to hw9.

Doing this homework you will learn how to use Exceptions. And you'll learn about automated testing. That's even more important.

  1. The call stack.

  2. JOI Exercise 7-21 (how much error handling code is there)? Read this exercise first, but do it last.

    Instructions here tell you how to comment your changes to Juno so that later on you will be able to count the lines of code that deal with error handling. The tool for that is class Profile:

    	>java Profile Shell
    	Class Shell
    	lines:                171
    	blank lines:          23
    	comment lines:        60
    	code lines:           88
    	error handling lines: 17
    
    So for this file, 17/88 = almost 20% of the code is devoted to error handling. Note that (23+60)/171 = almost 50% of the source file is devoted to comments or to blank lines that make the code easier to read. That fraction is typical of well documented code in industry.

    Use the Profile tool to answer these questions about Juno when you have completed the error handling:

    You can assume that all the Exception classes count as error handling code even though we haven't flagged lines there with the //EEE comment that Profile looks for when it counts lines.

    You do not have to read the code in Profile.java. All you need is Profile.class. Of course you can read it if you want to.

    Finally: what fraction of the Juno source do you estimate you have written in the last few homeworks?

    From: Ethan Bolker 
    Subject: why isn't Profile smarter?
    Date: Thu, 22 Apr 2004 16:06:29 -0400 (EDT)
    
    If I'd wanted to do more work I could have allowed
    
       java Profile Class1 Class2 Class3 ...
    
    or even
    
       java Profile *.java
    
    but I didn't. 
    
    You can improve Profile to do that if you like - and to have it sum the
    results and compute the percentages. Or you can do the files one at a
    time and do the totals yourself. That's what I recommend.
    
     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: RE: hw10
     > Date: Thu, 22 Apr 2004 19:46:30 +0000
     > 
     > 
     > Is there a way to test the fraction of comments and real codes just one time 
     > by running:
     > 
     > java Profile something. Or we need to test them one by one?
     > 
    
    
  3. JOI Exercise 7-ll (break Juno 7.5 as many ways as you can). The scripts you write should be part of your memo, along with the errors they cause. Then when you have fixed the error you can show (in your memo) how each script runs flawlessly. You can get lots of part credit for good test scripts even if you don't have the time or ability to fix the errors they find.

    We have written the test script for the newfile command: it's in file newfileTest.in. File newfileTest.out is the output from the command

    	java Juno -e < newfileTest.in 
    
    captured in an xemacs *Shell* buffer. (If you redirect the output with
    	java Juno -e < newfileTest.in > newfileTest.out
    
    then the ordinary output goes to the file but the error messages still appear where you are running the application.)

  4. JOI Exercise 7-13 (reworking error handling for missing JFiles).

  5. JOI Exercise 7-14 (preventing a user from overwriting existing JFiles).
       From: Ethan Bolker 
       Subject: what does remove remove?
       Date: Tue, 20 Apr 2004 14:23:01 -0400 (EDT)
    
       remove should remove only text files. rmdir (which isn't there and
       which you should not write) would remove only directories.
    
        > From: a classmate
        > To: eb@cs.umb.edu
        > Subject: hw10
        > Date: Tue, 20 Apr 2004 11:19:25 -0700 (PDT)
        > 
        > hello Prof. Bolker, the help for remove command tells that it
        > removes a TextFile. But currently remove also removes directory. Do
        > we have to fix it so that it removes only text files.  
    

  6. JOI Exercise 7-16 (fix all the ShellCommand errors you can find ...).
    From: Ethan Bolker 
    Subject: empty textfile?
    Date: Wed, 21 Apr 2004 12:49:23 -0400 (EDT)
    
    Excellent question.
    
    The command
    
    mars:> newfile foo
    
    should create an empty textfile. The TextFile class already provided
    the constructor you need.
    
    
     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: textfile
     > Date: Wed, 21 Apr 2004 11:45:38 -0400
     > 
     > Hello professor,
     > 
     > Should the customer be able to create a textFile with no contents. Then the 
     > size will be 0 and when we type it, it prints nothing. Or should we ask 
     > customer that he is bound to enter some contents otherwise the file ill not 
     > be created.
    
    

  7. JOI Exercise 7-12 (and a little more). Manage the Juno errors that can happen when bad input is provided at the login: prompt: You may want to do this with Exceptions, or some other way.

  8. Optional. JOI Exerecise 7-20 (file permissions). This requires quite a bit of design. Most systems with these kinds of permissions distinguish between permissions the owner has and those granted to others. The owner gets to change the permissions. You have to decide what you want Juno to do, and then decide on a user interface. What commands will you need? What error messages?

    You should write input scripts and what you expect for output from each one before you write any code. In fact, you'll get lots of this optional credit if you just write those tests and don't write any code at all!