CSCD 226 NAME_______________________
(Mini) Exam 3 Section______
50 points possible
int superFact(int N)
if (N <= 1)
return 1; //base case
return N * superFact(N – 1) * superFact(N – 2); //recursive case
a) The Fibbonacci value of 0 is defined as 0
b) The Fibbonacci value of 1 is defined as 1
c) All subsequent Fibbonacci values are calculated by adding the two previous Fibbonacci values together. So the Fibbonacci value of 2 is the Fibbonacci value of 1 plus the Fibbonacci value of 0 (for a result of 1). The Fibbonacci value of 3 is the Fibbonacci value of 2 plus the Fibbonaci value of 1 (for a result of 2). This means that the Fibbonacci value of some number N (N >1) is calculated by adding the Fibbonacci value of N-1 to the Fibbonacci value of N-2.
Write a recursive method called Fib that will compute the Fibbonacci value of an integer N that is passed into it. The method should return this value (which will also be an integer). You are guaranteed that N will be positive. As an example, an initial call to the method as follows: System.out.println(Fib(6)); should print a result of 8. Use the back of this page if necessary.
public static void main(String  args)
inFile = openInputFile(); //problem 3
readContents(inFile); //problem 4
catch (FileNotFoundException ex)
System.out.println(“Input file not found! Program will terminate.”);
catch (IOException ex)
}//end main method
a) gets the name of an input file from the user (3 points extra credit if you do NOT use the Keyboard class)
b) opens the input file
c) returns a BufferedReader object that is associated with the input file
d) accounts for (but does not handle) any exceptions that may be thrown as the result of the above actions
Be sure and declare all variables necessary for the method to function correctly!
a) reads lines of text (one at a time – you do NOT have to do this recursively!) from the BufferedReader object until the end of the file is reached
b) parses each line read for a string that represents the day of the week followed by an integer that represents the high temperature for that day
c) the above information (day and high temperature) should be written to the monitor, nicely formatted
d) the method should account for and handle any exceptions that result from parsing
e) the method should account for (but does NOT handle) any exceptions that result from reading operations from the BufferedReader object.
You are guaranteed each line in the input file will contain two entries per line. You are guaranteed the first entry will be a day of the week (a string). The second entry on the line (the temperature) may not be an integer. The entries will be separated by a space.