CSc 10: Introduction to Computing
Final Exam sample questions
Answer the following
T or F. Explain why or why not. (3 each, 45 total)
See http://www.cse.lehigh.edu/~glennb/um/book/exsolnew.htm.
What is an advantage
of value parameters?
What are two
advantages of reference
parameters?
Write a method which, given an String, converts all the ‘.’ (periods) into ‘.’ (commas)
and returns the new String. Note: do not use any library functions other than length, charAt and setCharAt.
In each of the
following code fragments: a) find and explain a bug, b) fix it (by marking up
the code on this sheet), and c) show your corrected version's output.
const int Sentinel = -1;
int count=0;
float sum=0;
int score;
System.out.println("Enter scores, stopping with
–1:");
while (score != Sentinel)
{ score = Input.getInt();
count =
count + 1;
sum = sum +
score;
}
System.out.println(count + " scores averaging
" + sum / count);
//Assume user types in: 70 81 -1
static void switchEm(int
x,int y)
{ int temp=x;
x = y;
y = temp;
}
public static void
main(String args[])
{ int a=1,b=2;
switchEm(a,b);
System.out.println("Now " + a + " is bigger than
" + b);
}
Explain why multiprogramming can improve the performance or Athroughput@ of each of the following types of systems:
a) Batch operating systems
b) Time-sharing operating systems
6. Consider the
following snippet from the atm_oop program:
public class Account
{ public Account() {}
public int getPIN() { return PIN; }
void setPIN(int pin) { PIN = pin; }
protected int PIN; //Personal Identification Number
}
a) Given the above
class definition, define a variable, myAccount, of this type, then assign it a PIN.
b) Why is the
following snippet illegal? Why is
making it illegal a good idea?
if
(myAccount.PIN == 2468)
c) Derive another
class, Savings, from class Account.
Declare a constructor for your new class which requires a PIN
number.
d) How do classes
illustrate the power of abstraction?
e) How does class
inheritance further illustrate abstraction?
Th.. th.. th.. that's all folks!