Final Exam Review
Tom Kelliher, CS 116
Dec. 12, 2000
Lab 7 due yesterday.
PostLab 7 due tomorrow.
Toolbox due Friday.
Final Friday in Kelley Lecture Hall, 3:00-5:00pm.
This example pulls together a lot of what we've done this semester.
- A stack is a fundamental data structure in CS.
- Last in, first out (LIFO) principle: like a stack of trays in a
cafeteria line.
- Stack parameter: number of items stack can hold.
- Stack state: data within the stack (array), top of stack.
- Stack operations: empty, full, push, pop.
Integer stack implementation:
import java.applet.*;
public class Driver extends Applet
{
Stack s;
public void init()
{
int tempI;
boolean tempB;
s = new Stack(10);
tempB = s.empty(); // Returns true.
s.push(12);
tempB = s.empty(); // Returns false.
s.push(9);
tempI = s.pop(); // Returns 9.
tempI = s.pop(); // Returns 12.
tempB = s.empty(); // Returns true.
}
}
class Stack
{
int topIndex;
int data[];
public Stack(int length)
{
topIndex = -1;
data = new int[length];
}
boolean empty()
{
return topIndex == -1;
}
boolean full()
{
return topIndex == data.length - 1;
}
int pop()
{
if (empty())
{
// Throw an exception and return.
return 0;
}
else
return data[topIndex--];
}
void push(int newTop)
{
if (full())
{
// Throw an exception and return.
}
else
data[++topIndex] = newTop;
}
}
- Iterative execution: for, while, and do/while loops.
When to use?
Index variable.
- Conditional execution: if/else if/else, switch, break.
Purpose of the break within a switch case.
- Conditions --- keys to the above. Precedence, associativity,
operators.
Remember the precedence table.
- Arithmetic: Operators and their types. Type conversion: implicit and
explicit casts.
- Parameter passing: Formal and actual parameters.
- Pass by reference vs. pass by value.
- Local variables.
- Return values and the type of a method.
- Special applet methods: init, paint, interface methods for listeners.
- Special class methods: The constructor.
- Primitive types: int, double, boolean, char, etc.
- Arrays: Type, number of elements, declaring, indexing, .length.
- Objects: String, Label, TextField, etc.
Creating your own.
- Declaring and instantiating. The actual variable or a reference?
- Variable/Object scope. Naming clashes:
double average(int data[])
{
double average; // dohhh....
- What is the model?
- Which object, which action?
- extends, inheritance, sub- and super-classes. Overrides.
- Public vs. private. Why use?
- The use of instance variables
The use of the constructor.
- Types of events.
- Listener classes must implement all interface methods. Interface
methods must have code to deal with each event from each object.
- Objects must register their events and designate handler objects.
Thomas P. Kelliher
Tue Dec 12 09:19:29 EST 2000
Tom Kelliher