CS51 - Spring 2010 - Lecture 27
admin
- Final exam: Monday, May 10 at 2pm in this room
- No more TA office hours
final review
- closed book, closed notes, etc.
- comprehensive, though, I'll bias it towards the later material in the course
- I will give you copies of:
- Objectdraw quick reference
- GUI cheat sheet
- Streams cheat sheet
- types of questions
- code this up problems
- what does this code do problems
- short answer questions
- topics (roughly)
- basic programming
- variables
- instance
- local
- constants
- methods
- classes
- parameters
- commenting
- basic constructs
- booleans
- ints and doubles
- loops
- other programming concepts
- active objects
- defining and manipulating multiple classes
- GUIs
- randomness
- colors
- images
- audio
- interfaces
- Recursion
- structural
- procedural
- Inheritance
- Arrays
- one dimensional
- two dimensional
- Strings
- Exceptions
- I/O
- file
- streams
- networking
- Sorting/asymptotics
Practice problems:
Given the class definitions below:
public class A{
public void method1(){
...
}
}
public class B extends A{
public void method1(String a){
...
}
public void method2(){
...
}
}
public class C extends B{
public void method1(){
...
}
}
private A someA;
private B someB;
private C someC;
- what assignments are legal?
- Is someC.method2() a legal call?
- Which classes method1 is called for:
---- someB.method1();
---- someC.method1("this is a string");
What would the call mystery(5) return?
public String mystery(int num){
if( num <= 1 ){
return "1";
}else{
String returnMe = "";
for( int i = 0; i < num; i++ ){
returnMe += num
// returnMe = returnMe + num;
}
return returnMe + mystery(num-1);
}
}
What does the following method return with the input: [1, 2, 3, 4, 5, 6, 7, 8]?
// length of a is assumed to be even
public int mystery(int[] a){
int returnVal = 0;
for( int i = 0; i < a.length/2; i++ ){
returnVal += a[i] * a[a.length-i-1];
}
return returnVal;
}
what does the method below do?
public int[] mystery(int[][] a){
int[] returnMe = new int[a.length];
for( int i = 0; i < a.length; i++ ){
int s = 0;
for( int j = 0; j < a[i].length; j++ ){
s += a[i][j];
}
if( s > 100 ){
returnMe[i] = s;
}else{
returnMe[i] = 0;
}
}
return returnMe;
}
Why should you use the StringBuffer class?
One of the methods below will not compile. Indicate which one and explain why.
public void methodA(){
...
throw new IOException();
}
public void methodB(){
...
throw new NumberFormatException();
}