CS 1063 Intro. to Programming
Topics and Review Questions for Final Exam, Fall 2005
|
Added on Saturday, 10 Dec. You should study for and while loops,
starting with #8 below (answers at a link on that page).
Then look at #4 and #5, at #2 and #3. All these are fairly easy.
After these, try #6. I give the answer to a simple version of #7, but
the full question is hard.
#9, and both projects in #10 are all pretty hard. If you are having
trouble in the course, you would be better off looking over some of the
simpler examples involving classes, since I'll have something about them.
(Good luck!)
Note: After you have worked on the problems below,
you can look at
Selected Answers.
Date and Length of Exam:
Tuesday, 13 December 2005, 1:30 pm - 4:15 pm.
Official Review:
-
Week 15 Lectures
gives initial review material.
You should work on the the "For Loops" material and
on Activities 1 and 3 in this lecture.
I have rewritten Activity 3 below on this page
under the heading "Sample Questions".
-
Week 16 Lectures
gives two old Project 3 assignments along with solutions,
for you to work on and look over.
Previous two reviews:
Outline of Topics after Second Review:
- Material you are responsible for:
- How to study: Do not just read the material
over, but instead start up JBuilder and try out many of the
pieces of code inside actual Java programs.
- Topics:
- Classes:
This remains the most important topic.
- See
Basic parts of a class: Student class
These include:
- A class that will be instantiated (using new).
- A class with a main method that
will do the instantiatino (with us, its name usually
has Test at the end).
- "Private data members" in the first class above.
They are also called "instance variables". (With us, the name usually
starts with my.)
- One or more "constructors", with "formal parameters".
The constructor name has to be the same as the class name.
- Various methods, including "public accessor methods"
(name usually starts with get), and
public and private helper methods. Methods have parameters
and we can declare "local variables" inside a method.
- Also see many worked-out examples on the page:
Extra Materials
- Data types (primitive and objects), operators on
primitive types, precedence of operators:
See Review for Exam2.
- if-else statements: See Lectures for weeks
10, and 11.
- loops: while, for,
do-while: See Lectures for weeks
13, 14, and 15.
Sample Questions:
I will pick simple questions about many of the topics
from the web pages and from class.
Often it will involve giving you some code and
asking you to explain, modify, or complete the code.
- classes: Probably some question about writing
a class to represent something, and writing a test class
to create an instance of the given class. This is what
we've been doing all semester long.
- primitive types and operators:
- Write Java code that will start with a certain
number of seconds, and will convert to
hours, minutes, and seconds, where "hours" and
"minuters" are as large as possible:
int time = 74747; // or some other value in seconds
int hours = ...; // fill in for ...
int minutes = ...; // fill in for ...
int seconds = ...; // fill in for ...
System.out.println(time + " seconds is\n " +
hours + " hours\n " +
minutes + " minutes\n " +
seconds + " seconds\n ");
if-else:
- Write a short if statement
(no else) that will check if
an int is inside the range from
2 to 10 (inclusive)
and will print "In range" if this is so.
- Write another short if statement
(no else) that will check if
an int is not inside the range from
2 to 10 (inclusive)
and will print "Out of range" if this is so.
loops:
- Translate the following while loop
to a for loop
that does the same thing:
int i = 1;
int sum = 0;
while (i < 10) {
sum = sum + i*i;
i++;
}
System.out.println("sum: " + sum);
- Translate the following for loop
to a while loop
that does the same thing:
for (int k = 10; k >= 1; k--) {
System.out.print(k);
// Note: below was "k != 10" in error earlier
if (k != 1) System.out.print(", ");
}
System.out.println();
- Redo the example that we worked on in class:
use a for loop to calculate 100000
terms of the following sum.
Compare the result with
Math.PI*Math.PI/6.0.
1 + 1/22 + 1/32 + 1/42 + 1/52 + ...
- Write a code segment in Java that will start
with an amount of money (a double amount), and a number
of years (an int years), and
an interest rate (a double rate).
Use a loop to get the amount of money at the end of this time,
applying the interest each year.
Compare this amount with the amount you would have
if you applied the interest 4 times a year.
(You apply 0.25*rate a number
times equal to 4*years.)
- Here are some more sample questions:
Practice with loops.
Answers.
Just focus on the "First Starting Point" and the
"Second Starting Point": this amounts to 6 exercises for
"while" loops and 6 for "for" loops.
Everything (classes, if-else, loops, operators):
- Activity 3:
the TeacherSalary Class.
(taken from the Week 15 lecture).
- Two old Project 3 assignments along with
solutions: Review
Projects. (This is the Week 16 lecture.)