CS1021
Homework

Homework is not required, but you may find these practice problems helpful.

Week 1 (Review)

Week 4

This homework assignment is especially designed to help you get more practice with the material.

Week 6

The assignment:

  1. Is this a legal assignment? (Will it compile?)
    Object o = new JButton();
    Why or why not?
  2. On exam I, problem 11, why is a cast to the Circle type required to Circle or Shape required when implementing the Circle class's equal method? (If you do not have a copy of exam I, please ask me or infer the problem from what's here.)
  3. In the statement
    JButton b1 = new JButton("Hello");
    JButton b2 = b1;
    1. How many buttons are created? Why?
    2. But there are two button variables! How can that possibly be the answer? (Explain)
  4. Is an Interface a Class? Answer either yes or no, and support your claim.
  5. Into IntelliJ, include an instance variable in an interface. You can even make it public! Can you set this variable from main? (Does it work?) Provide theory to support your experiment. (One sentence is fine.)
  6. Redo this assignement from last week: Get your example JFrame application to compile with two components. You should have at least one component respond to a user’s action. This is just completing an in-class example, no more than that. Then print your source code and include it with your homework. (I will return your previous assignment, so you can simply re-use last week's if it worked.) Hints: Implement ActionListener. See in-class examples
  7. Implement the "max" method from scratch. Given an ArrayList or ArrayList, write a method to find the maximum int (or longest toot) without using collections. If you have already done this, just copy-paste your solution from the lab. (Ideally your lab will already have a method taking an ArrayList of T00ts, so the code is easily re-usable.) Hint: You only need to walk over the list once, and temporary variables can be helpful.

Week 7

Homework proper

Fill out the example exam and turn it in as follows:

In class

This homework was specifically designed for Week 7, Class 1.

From the book:

  • Excercise 15.1 from the book (Chapter 15, exercise 1). This is a code-reading problem. We worked the highlighted problems in class
  • Ex 15.2 (code reading, simple extension of 15.1)
  • Ex 15.3 (code writing)
  • Ex 15.4 (code writing, deeper than 15.3)
  • Ex 15.6 (rearrange catch blocks) (There are multiple correct solutions)
  • Ex 15.7 (Fig. 15.14 on pp. 685-686)
  • Ex 15.8 (code reading)
  • Ex 15.9

Week 8 HW

Print this handout and fill in your answers. If you staple the assignment, you do not need to write your name on each page. (And stapling is a requirement.)

Week 9 HW

  • Part a (covered on Week 10 Tuesday quiz)
  • Part b (TBA, covered on Thursday quiz)

Week 10 HW: Functional Programming

Functional Programming:

Acknowledgement

Dr. Taylor wrote the Week 1 homework assigment, and some of the other problems as well. Some problems are inspired or directly copied from the book. These are not cited to reduce the confusion about how they should be numbered when turned in.