CS 161: Introduction to CS/OOP/Java
Winter 2001 -- Dr. Burnett
Homework/Workshop #2
Due: Wednesday, Jan. 24, 2:00 p.m. Update: extended to Jan. 25, 2:00 pm


How to turn it in: Follow the instructions for each problem, and turn in the files electronically as instructed on the web page


Problem 1 is a workshop problems to get your lab skills ready for writing applications, which you will need for a programming assignment soon.
 

1. [10 pts] Do the lab exercise on pp. 105-106, using Code Warrior. (The Circle class problem). There should be an application file (patterned after RectangleUser in Chapter 1) and a separate class file Circle.java.  You only need to turn in the Circle.java file.

We have chosen this 2-file set-up (1) to give you experience designing a class separately from the application it happens to be needed for today, so that you will think more about re-usability of your classes and other applications that might use them and (2) to make sure you are comfortable with programs that use more than 1 class file.

Note : Please make sure that your code follows the following naming conventions:
(You do not have to resubmit if you already submitted your homework.
This is only for people who have not previously submitted their
homework.)

Java file name : Circle.java
Constructor : Circle (double radius)
Accessors: public double calculateArea()
                  public double calculateCircumference()
                  public double calculateDiameter()
Mutators  : public void setRadius(double)
                  public void setDiameter(double)



For the remaining problems, turn in a single text file (Homework2.txt) containing the answers to all the questions. For problems 2-4, if you explain your answer (i.e., give a whole sentence instead of just 1 phrase), it will be easier for us to give you partial credit.

2. [5 pts] Do exercise 3, p. 111.

3. [5 pts] Describe the relationship we want among subclasses.  For example, how do we know something should be a subclass of another class?

4. [5 pts] Why is encapsulation and information hiding important for programs?  How can we achieve these in Java?