CS 141 Fall 2012 -- Second midterm review

How to prepare? Reread Chapter 5 (review the terms at the end). Redo the meltFrosty lab without looking at the answer.
And... make sure you can answer the Review Questions in Chapters 5-9.
Here's something somebody who knew molecular biology and computing made!
General questions:
  1. What are the two main things that are defined in a class?
  2. What are seven statements we have covered so far?
  3. What is the syntax of a method heading?
  4. What is the syntax of a method body?
  5. Why are good names important?
  6. How do you make a TextField that responds to the user hitting Enter in it?
  7. How do you make a method a class method?
  8. What is the difference between class and instance methods?
  9. What are two build-in class methods we have used?
  10. Name three primitive types.
  11. Name ten built-in classes.
  12. Name three problem solving techniques from the text.
  13. What is the ABC technique? What are the three steps?
  14. List 12 operators in order of precedence (highest first)
  15. What does casting do?
  16. What are infinite loops good for?
  17. Write pseudo code for a method to return its String parameter backwards.
  18. Write pseudo code for all the methods in "programming questions", below.
  19. What is the difference between syntax and semantics?
  20. What is the syntax of a return stmt?
  21. What is the syntax of a message stmt?
  22. What is the syntax of a block stmt?
  23. What is the syntax of a if stmt?
  24. What is the syntax of a while stmt?
  25. What is the syntax of a assignment stmt?
  26. What is the syntax of an empty stmt?
  27. What is the syntax of a method declaration?
  28. What is the semantics for a return stmt?
  29. What is the semantics for a message stmt?
  30. What is the semantics for a block stmt?
  31. What is the semantics for an empty stmt?
  32. What is the semantics for a if stmt?
  33. What is the semantics for a while stmt?
  34. What is the semantics for a assignment stmt?
  35. What is the semantics for a method declaration?

Programming questions:
  1. Write a method, called even, that returns true or false depending on if its int parameter is even or odd.
  2. Write a method that outputs all the numbers from 1 to a million to System.out.print (sout), one per line.
  3. Write a method that outputs all the numbers from 1 to a million to sout, 10 per line.
  4. Write a method that outputs all the even numbers from 1 to a million to sout, one per line.
  5. Write a method that outputs all the even numbers from 1 to a million to sout, 17 per line.
  6. Write a method that outputs all the even numbers from 1 to a 1000 to sout, as many as fit on each line.
  7. Write a method that prints the characters in its String parameter, one per line in order from first to last.
  8. Write a method that prints the characters in its String parameter, one per line in order from last to first.
  9. Write a method that prints every other character in its String parameter, one per line, starting with the first one. So, if the parameter were "frobot", it should output f o o (one per line).
  10. Write a method that returns every other letter of its string parameter, in a String. So, if the parameter were "frobot", the returned String should be "foo".
  11. Write a method called firstFirst that is passed two String parameters and returns true or false depending on if its first parameter comes first alphabetically.
  12. Write a method called reverse that returns its String parameter backwards.
  13. Write a method, named countOccurances, that has a String, and a char parameter, which returns the number of times the char occurs in the String.
  14. Write CharCounter class with two variables, one for the char you are counting, one for the counter. Include an inc() method (which increments the counter), and a getCount() method (that gets the count!).
  15. Write a method, countFrequencies, which is passed a String, and returns an ArrayList containing 26 CharCounters (for 'a' to 'z'), each of which has its counter set to the number of occurances of that letter
  16. Assuming you have a working countFrequencies (above) method, use it to write a method which is passed a String and returns the letter that occurs most often in that String
  17. Write an Account class with a String name variable and an int balance variable. Write the accessors for both. Write an initializing constructor. Write a void withdraw(int) method that reduces the balance by the parameter, unless that would make the balance negative (in that case do nothing).
  18. Write a method that is passed two Accounts and returns the one with the larger balance
  19. Write a method that is passed four Accounts and returns the one with the largest balance
  20. Write a method that is passed 16 Accounts and returns the one with the largest balance
  21. Write a Person class, that has an int age variable, and an Account variable with accessors and an initializing constructor.
  22. Write a method called robotBouncer which is passed a Person. If they are 21 or over and have at least $10 in their Account, greet them by name and invite them in; otherwise rudely say "go away!".
  23. Write a method called corruptRobotBouncer which acts just like the robotBouncer except it will also allow anyone in so long as it can withdraw $1000 from their account (i.e. if their balance is more than $1010).
  24. Write a method called okayToEnter, which is passed a Person and returns true if they are over 21 and have at least $10.
  25. Write a method called corruptOkayToEnter, which is passed a Person and returns true if they are over 21 and have at least $10 or they have at least $1010 in their Account.
  26. Of the two corrupt methods, which was easier to write? Why?

Older midterm (with answers!)

2007

Newer midterm (with answers!)

2010