Make sure you can answer all the Review Questions at the end of Chapters 1-5 & 7-8!
(psst! there is good reason to believe that at least one question from each of those chapters will
appear on the final...)
Review the first review and the second review
(psst! at least two questions from there will
appear on the exam too)
Recapitulation (again)
Before a person can program in Java, there are a few dozen concepts that
must be understood. They were covered in Chapter 5 (as well
as in class).
Below is a list of those; I recommend that you read this list every day until all of those concepts are
very obvious. If any are not clear, look at explanations in Chapter 5 (in the section titled,
Recapitulation).
Information
types
values
variables
expressions
Language Elements
classes
variables
methods
constructors
objects
statements
message
assignment
return
if
while
for (old and new)
identifiers
methods/messages
signatures
parameters (formal/actual)
parameter linkages
syntax (of the statements, and class definition)
semantics (of the statements)
Process
editing
compilation
execution
debugging
prototyping
Sample questions:
When is public static void main(String[]) executed?
What are seven Java statements we have encountered?
Explain the cookies and cookie-cutter metaphor.
What is the actor metaphor?
How do you instantiate an object of type Foo?
What are the four primitive types we have used?
How do you send information to a method?
Inside a program where is information stored?
How do you declare a variable?
How can you change the value of a variable?
What are 5 problem solving techniques presented in class?
What are two techniques for software reuse?
Why is programming so difficult when you first start?
What does cognitive overhead have to do with programming?
What happens if you declare a object variable and send it a message before it is initialized to something besides the default value?
What is the difference between compile-time and run-time?
Is casting a runtime or compile-time operator?
Assume you have an int variable, score; write Java code to either sout "pass" or "fail"
depending on whether score is more than 60.
Assume you have an int variable, x; write Java code to sout "yes"if x is 17 and do nothing otherwise.
Write a while loop that will output the numbers 1-1000, one per line.
Write a method, daysInDecember, with no parameters, that returns 31.
Write a method, lameDuck, with no parameters, that returns "shrub".
Write a method, ignorantOfJava, with no parameters, that returns false.
Write a method, jackpot, which returns a million times the value of its int parameter.
The final in this course is worth twice as much as the midterms.
Write a method, examScore, which is passed 3 ints (mid1, mid2, and final), and returns the
weighted average of the three (as a double; make sure it *is* a double!).
Write a method, passingAverage, which is passed 3 int parameters (as above) and returns true just if their
weighted average is more than 60.
What are four types of variables?
in this code which variables are of which type?
class Foo {
int instanceVariable;
static int classVariable;
void bar(int parameterVariable) {
String methodVariable = "method";
}
Write a method, secondVowel, with a String parameter, which returns either the second vowel in the param, or '?' if
there aren't at least 2 vowels.
Write a method, lastChar, with a String parameter, which returns the last character of its parameter.
Write a method, doubleVision, with a String parameter, which returns its parameter but with two copies of each character.
if the input were "hello!", the return should be "hheelllloo!!"
Write a method, mostZs, with two parameters, an ArrayList<String> and a char, which returns whichever String in the list has the most of that char.
A "complete" class, for the next questions means one with variables, accessors for each, toString(), and an initializing constructor.
Write a complete Song class including variables for name and
playing time (in seconds).
Write a complete CD class, which contains a list of Songs and the artist
A CD store would have a number of CDs in stock. To keep inventory, they would want to keep track of the CDs they have. Write a complete Item
class, which has variables for the CD, how many are in stock, and the price.
Write a complete Inventory class, which has a list of Items.
Write a complete Store class, which has an inventory and a web address (a String).
A large company might have many stores. Write a complete Chain class, which has in it a list of Stores, as well as the name of the chain
Write a method that is passed a Chain and returns the Store in it with the largest inventory (by dollar value).
Write a method that is passed a Chain and returns the CD in it with the largest inventory (by number).
Write a method that is passed a Chain and returns the CD in it with the largest price.
Declare an ArrayList of Foo objects
Iterate over it and send each element the bar(int) message
Could this be a legal Java statement? littleBunny.fooFoo(hoppingThroughTheForest, scoopingUpFieldMice, boppingEmOnTheHead); if not, explain why not, if so
write the code to establish a context in which it would compile.
Write a method that is passed an ArrayList<String> and returns the character that occurs the most frequently in that list.
Write a method that is passed a String and returns the character that occurs the most frequently in that String and its frequency
(since methods may only return one thing, this may seem to be a bit of a problem --
if you create another class with a char and an int variable in it, the problem is solved).
Assume you have a database of Accounts, stored in an ArrayList<Account>. Each Account has a String name and an int balance.
Write a method to return the Account with the largest balance.
Write a method, find, that is passed a String and returns the Account with that name, or null if it is not found.
Write a method to delete the Account with the largest balance.
Write a method to add a dummy Account with twice the largest balance in the list.
Assuming that method was invoked repeatedly and initially the largest Account had $2 in it,
how many repetitions before the dummy Account would have a negative balance? Why?