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

Due: Thursday, February 12, when labs close.

Files to turnin:

Some of these problems are quite straightforward. Some are subtle.

  1. JOI Exercise 2-1 (of course). Use a different floppy (or a different folder on your zip drive) for this homework - in particular, for this memo.txt .

    Remember to pay attention to spelling and grammar in your memo. Since the spell checker in emacs isn't working yet, could consider pasting the contents into MSWord (available on the lab machines), checking the spelling there and then pasting back into emacs. Clumsy, but maybe worth the effort. Or get a friend to proofread.

  2. Class Temperatures is discussed in Chapter 2 of JOI. You can find the source code on the JOI web page or the CD. Find all the places in Temperatures.java in which a message is sent to an object that's not a Terminal . (There are so many of those that including them in this discussion would be tedious.) For each one, identify In class we'll discuss what this code does (the semantics) but you should be able to answer this question just from the structure on the page (the syntax).

  3. Explain the color coding used for various kinds of tokens in Java programs

  4. JOI Exercise 2-3. Discuss lines 64-67 of LinearEquation.java instead of lines from BankAccount.java .

    In class we'll discuss what this code does (the semantics) but you should be able to answer this question just from the structure on the page (the syntax).

  5. JOI Exercise 2-12.

  6. JOI Exercise 2-13.

  7. JOI Exercise 2-20.

    Your output match the sample output in the text exactly (except for the question marks at the end - provide the right answers there) since we will use our computer to see whether the output from your program is exactly the same as the output from a correct program. So to get full credit, you need to make sure that the program prompts are just what we've specified. It's not enough to get the correct numerical answers.

    Here is the sample output (copied from JOI). You can cut the prompts from this web page and paste them in as quoted strings in your Java program. That's a way to make sure they are right, with no chance for a typing error. The program's output is in bold face.

    	Basic rate (in dollars): 30
    	Cost per message unit (in cents): 5
    	Number of message units: 101
    	Phone bill is: $35.05
    	Amount willing to spend (in dollars): 40
    	Maximum number of message units: ???
    

  8. Learn something new and useful or interesting about working in emacs, and describe what you learned.

  9. Optional. JOI Exercise 2-22.

    Note: optional problems really are optional. We don't add the points you earn on them to your score for the homework (if we did, they wouldn't be optional). We'll keep track of the optional work you do, and if at the end of the semester you're just on the borderline, say, between an A and an A-, optional work can tip the balance. But they won't help if you're on the borderline between a C and a C+. If that's where you find yourself you should have spent more time on the regularly assigned work!


     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: hw2
     > Date: Thu, 5 Feb 2004 18:34:02 -0500
     > 
     > I have a question about homework 2 part 2 where you ask us 
     > to identify all the places in Temperatures.java in which a 
     > message is sent to an object that is not a Terminal. I was 
     > wondering if this included messages sent to a terminal 
     > object whose information is a message to an other object? 
     > Such as the line of code that follows.
     > 
     > terminal.println( c2f.compute( 0.0 ) );
     > 
     > Would you want the compute message sent to the 
     > LinearEquation object called c2f identified even though it’s 
     > the information being sent with the println message?
     > Thank you for you time, Sean.
    
    Good question. println is a message sent to the Terminal object
    terminal so you need not discuss it. But c2f.compute is a message sent
    to c2f. The corresponding method returns the information the println
    nessage needs to send along to the Terminal.
    
    Remember that Java is case-sensitive, so Terminal and
    terminal are different identifiers. You use the wrong one in your
    question where you speak of a "terminal object". You should say
    "Terminal object" or "the terminal".
    
    
    From: Ethan Bolker 
    To: eb@cs.umb.edu
    Subject: PhoneBill clarification
    Date: Tue, 10 Feb 2004 17:20:21 -0500 (EST)
    
    The restriction "no arithmetic in PhoneBill.java" can't be taken too
    strictly. You will have to convert cents to dollars, which requires
    arithmetic.
    
    And do allow a fractional number of message units for the maximum that
    can be purchased for a fixed amount. Don't attempt to round to an
    integer. Let Java provide as many decimal places as it wants to.
    
    
    From: Ethan Bolker 
    Subject: what can you edit?
    Date: Thu, 12 Feb 2004 15:27:32 -0500 (EST)
    
     > From: a classmate
     > To: eb@cs.umb.edu
     > Subject: hw2 question about editing LinearEquation...
     > Date: Thu, 12 Feb 2004 12:22:26 -0800 (PST)
     > 
     > Can we edit LinearEquation and create one or two other algebra
     > functions or are we not to touch LinearEquation at all? Thanks.
    
    This is an important question with a straightforward answer: NO. 
    
    The main point of the exercise (and of object oriented programming in
    general) is to learn to use the features a client class offers you
    in its API, without changing that class at all.
    
    We will test your PhoneBill class with our LinearEquation class. 
    
    You can discuss in your memo what changes you would like to make in
    LinearEquation and why.