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!
- Some of these questions will appear on the exam.
- Not all of these questions will appear on the exam.
- Some exam questions do not appear in this list!
- Be sure you can answer all the review questions in the chapters!
- Bring questions to class at the beginning of week 12.
General questions:
- What are the two main things that are defined in a class?
- What are seven statements we have covered so far?
- What is the syntax of a method heading?
- What is the syntax of a method body?
- Why are good names important?
- How do you make a TextField that responds to the user hitting Enter in it?
- How do you make a method a class method?
- What is the difference between class and instance methods?
- What are two build-in class methods we have used?
- Name three primitive types.
- Name ten built-in classes.
- Name three problem solving techniques from the text.
- What is the ABC technique? What are the three steps?
- List 12 operators in order of precedence (highest first)
- What does casting do?
- What are infinite loops good for?
- Write pseudo code for a method to return its String parameter backwards.
- Write pseudo code for all the methods in "programming questions", below.
- What is the difference between syntax and semantics?
- What is the syntax of a return stmt?
- What is the syntax of a message stmt?
- What is the syntax of a block stmt?
- What is the syntax of a if stmt?
- What is the syntax of a while stmt?
- What is the syntax of a assignment stmt?
- What is the syntax of an empty stmt?
- What is the syntax of a method declaration?
- What is the semantics for a return stmt?
- What is the semantics for a message stmt?
- What is the semantics for a block stmt?
- What is the semantics for an empty stmt?
- What is the semantics for a if stmt?
- What is the semantics for a while stmt?
- What is the semantics for a assignment stmt?
- What is the semantics for a method declaration?
Programming questions:
- Write a method, called even, that returns true or false depending on if its int parameter is even or odd.
- Write a method that outputs all the numbers from 1 to a million to System.out.print (sout), one per line.
- Write a method that outputs all the numbers from 1 to a million to sout, 10 per line.
- Write a method that outputs all the even numbers from 1 to a million to sout, one per line.
- Write a method that outputs all the even numbers from 1 to a million to sout, 17 per line.
- Write a method that outputs all the even numbers from 1 to a 1000 to sout, as many as fit on each line.
- Write a method that prints the characters in its String parameter, one per line in order from first to last.
- Write a method that prints the characters in its String parameter, one per line in order from last to first.
- 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).
- 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".
- 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.
- Write a method called reverse that returns its String parameter backwards.
- 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.
- 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!).
- 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
- 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
- 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).
- Write a method that is passed two Accounts and returns the one with the larger balance
- Write a method that is passed four Accounts and returns the one with the largest balance
- Write a method that is passed 16 Accounts and returns the one with the largest balance
- Write a Person class, that has an int age variable, and an Account variable with accessors and an initializing constructor.
- 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!".
- 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).
- Write a method called okayToEnter, which is passed a Person and returns true if they are over 21 and have at least $10.
- 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.
- Of the two corrupt methods, which was easier to write? Why?
Older midterm (with answers!)
2007
Newer midterm (with answers!)
2010