CS7 Exam 2 - Review Sheet


Exam 2 will cover chapters 3 and 4 in JBD and will be similar in format to the first exam.  It will contain questions from 3 categories:  conceptual, code understanding, and code writing.  To prepare, you should review everything you can find:  your notes, recorded lecture notes, the book, recitation handouts, programming assignments, etc.  I always advise people to maintain a list of concepts and vocabulary so that you aren't stumped by this on the exam.  Often times there will be a word used in a true/false or other kind of question that depends on your understanding of a term.  When asked on exam day, sometimes I have to say "that was something I felt you should have known."  It's tough, but don't gloss over the basics and you'll be fine.

The review questions at the end of each chapter are excellent.  All of them are good questions, but a few in particular:
As usual, the code writing portion of the exam will be the most difficult.  Here are few sample questions:

  1. Write a method that accepts two strings as parameters and displays them with a blank line in between.
  2. Write a code segment that checks to see if the integer num1 is odd, and if so, sets it to zero.  If num1 is even, then decrement it by one.  Try to do this with only one boolean expression (i.e., if you know the number is not odd, then it has to be even).
  3. Write a loop that prompts the user for an integer, and continues looping until they provide a positive number.
  4. Write a code segment that prompts the user for two positive integers.  Then, write a for loop that prints all the numbers between 0 and the first number, increasing by the number specified by the second integer.  For example, if you get 17 and 4, the output would be:  0, 4, 8, 12, 16.
  5. Write a method that determines if a number is divisible by another number (both are parameters).  For example, if the input is 6 and 2, the method would return true (a boolean).  2 goes into 6 evenly.  If the input is (for example) 17 and 5, return false.  5 does not divide 17 evenly (remainder of 2).
  6. Write a method that accepts 3 doubles and returns the product (multiplication) of the smallest two.  Feel free to use Math.min().
That should give you an idea.  In recitation, you will get practice writing methods from scratch.

There will at least one scope question, giving you a program and asking you to determine the output.  This program will have duplicate variable names and require you to follow the scope rules carefully.  See the code handout from class to get an idea of what these look like.  I have also specified a few in the list above (from the book) that will help.

Good luck studying.

last modifed 10/20/03, by hcl