This website is preserved for historical and scholarly reference and is no longer actively maintained.
Homework Assignments
CPSC 210 -- Spring 2003
The intention of these assignments is
(1) to persuade everyone to read the text books,
(2) to allow the instructor more time to emphasize major concepts and critical points in the text material,
and (3) to allow class discussions to introduce material not covered in the text.
Homework is due at the beginning of class. Homework will not be accepted or checked late.
The text of homework must be typed when so indicated.
Figures may be (probably should be) hand-drawn.
Homework must have the name of the person submitting the homework at the top of the first page.
All pages must be stapled together. Failure to follow instructions will result in deduction of points
(0.5 pt. for no name, 0.1 pt. for not correctly stapled).
Homework is to be done individually. The purpose of the
homework is to make it possible to cover the course material
effectively. Thus, it is important that each person read and
worked for themselves. If the instructor believes that homework has
been jointly written, on the first occurrence the grade will be
shared jointly among the writers. A second occurrence will be
considered academic dishonesty and appropriate action will be taken.
#1 (due Friday, January 10)
Read Chapter 1 of Java Elements and answer the following questions
1. What integer will be produced by 12 % 5 ? (1 pt.)
2. What integer will be produced by 5 % 12 ? (1 pt.)
3. What integer will be produced by 5 % 5 ? (1 pt.)
4. What will be the result of 12 / 5 ? (1 pt.)
5. How would you have a program print the amount of time it takes to run ? Give code and state page reference. (2 pts.)
6. What is the result of "Clem" + "son" ? (1 pt.)
7. What is the name of the operation in #6 ? (1 pt.)
8. Write code that will produce a random number between 0 and 9 inclusive. (2 pts.)
#2 (due Monday, January 13)
Answer the following questions related to Chapter 1.
1. If the variable salary is of type float, write a statement that
stores the value in salary in the int variable intSalary. (1 pt.)
2. The code on pages 21-22 prints a point at 2 o'clock on a clock
face (the circle). What single line of the program needs to be changed
to print a point at 1 o'clock on the clock face? (1 pt.)
3. What should that line read? (1 pt.)
4. What convention is followed in choosing the first symbol of a
variable name with respect to capitalization? (1 pt.)
5. If 'A' is assigned to a variable varOne, what type should varOne be? (1 pt.)
6. If "A" is assigned to a variable varOne, what type should varOne be? (1 pt.)
Read Chapter 2 (omit section 2.1 on the Console window and all use of the Console window) of Java Elements and answer the following questions:
7. Write code to draw a square of side 100 with upper left hand corner at (25, 25) by drawing 4 lines. (1 pt.)
8. Write code to draw a square of side 100 with upper left hand corner at (25, 25) by drawing an object of type Rect. (1 pt.)
9. Draw the result after each execution of "d.fill" for the code on page 57. Each drawing should have all vertices of the bounding rectangle clearly shown. (2 pts.)
Homework #3 -- due Wednesday, January 29
Discover a method of computing the tax for a single person without entering
all the numbers in the table on pages 25 - 29 of the instruction booklet
for Form 1040 EZ.
Homework #4 -- due Friday, February 14
Write a reflection (typed, bring to class) about the Tax assignment. Did this assignment help you become more familiar with Java?
What parts of the assignment were valuable?
What parts were not? Did this assignment help you understand
anything useful about taxation? ... Other comments you care to make.
Homework #5 -- due Monday, February 17
Probelm 7.6 on page 190. "Write a method that reverses the order of
elements in an array of ints." A good signature for this method
would be
public static void reverseArray ( int [ ] data )
// post: reverses the order of array, data
Note that the return type is void. You should test your method
to see if it works. Bring a printout of your method to class on
Friday. (Not accepted by email.)
Homework #6 -- due Friday, February 21
Turn in a (typed) plan of your milestones for Programming Assignment #4.
This plan should include which methods and testing (i.e., main method
components) you expect to have completed by date. Since you will
already have been working on the program, your plan should also
indicate which of the tasks in your plan have already been
completed by Friday.
Homework #7 (due Friday, February 28)
Read Chapters 10 and 11 of Java Elements and submit answers to the following
questions. This homework should be typed. (Not accepted by email)
- 1. What is a container class?
- 2. What is the purpose of threads in Java?
- 3. What is a Java Virtual Machine and why is it important?
- 4. Why is the Turing machine an important concept?
- 5. What is a P-RAM? What is it used for?
Note that we are skipping Chapter 9 in Java Elements. Since you
have a programming assignment due that night, you might choose
to finish this assignment early.
Homework #8 (due Monday, March 3)
Read chapters 0, 1 and 2 of Java Structures and submit answers to the following
questions. This homework should be typed.
- 1. What is the URL of the javastructures package?
- 2. How is data abstraction accomplished in Java?
- 3. What is a package? Give a good definition.
- 4. List all methods that must be implemented in a class that implements the
interface Collection.
- 5. When should your method have a precondition?
- 6. When should your method have a postcondition?
Homework #9 (due Wednesday, March 5)
Problem 3.6, page 47, Java Structures. Your reverse method should
have as small a growth rate (with the size of the Vector) as possible.
Extend Bailey's Vector class and write the method as follows:
import structure.Vector;
public class ExtendVector extends Vector
{
public ExtendVector ( )
{
super ( );
}
public void reverse ( )
// post: reverses the contents of this Vector
{
}
}
Homework #10 (due Wednesday, April 23)
Please type your answers.
Problem 4.1, page 73. Assume Bailey's Vector class.
Problem 4.2, page 73. Assume Bailey's Vector class.
Problem 4.3, page 73. Include an explanation of your conclusion.