CS1021
Homework
Homework is not required, but you may find these practice problems helpful.
Week 1 (Review)
- Easier ones
- CodingBat: shiftLeft
- CodingBat: tripleUp
- CodingBat: copyEvens
- CodingBat: lucky13
- CodingBat: sum28
- CodingBat: centeredAverage
- The above centeredAverage problem with an ArrayList instead. (
public int centeredAverage(ArrayList<Integer> nums)
)
- Harder ones
- Exercise: 10.7, 10.9, 10.10
- Exercise: 10.10
- Project: 10.2
- Project: 10.7
Week 4
This homework assignment is especially designed to help you get more practice with the material.
Week 6
The assignment:
- Is this a legal assignment? (Will it compile?)
Object o = new JButton();
Why or why not? - 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.)
- In the statement
JButton b1 = new JButton("Hello");
JButton b2 = b1;- How many buttons are created? Why?
- But there are two button variables! How can that possibly be the answer? (Explain)
- Is an Interface a Class? Answer either yes or no, and support your claim.
- 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.)
- 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 users 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
- 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
Week 10 HW: Functional Programming
Functional Programming:
- CodingBat: copies3
- CodingBat: lower
- CodingBat: noLong
- CodingBat: two2
- CodingBat: noTeen
- CodingBat: square56
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.