Second midterm review
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 exam...)
Review the first review
(psst! at least two questions from there will
appear on the exam too)
Recapitulation (again)
There are a few dozen concepts that
must be understood before a person can program in Java. Most of them were covered in Chapter 5 (as well
as in class).
This list would be suitable to read every night after programming (you are programming
every night, right?) until it
becomes very obvious. If any are not clear, look at explanations in Chapter 5 (in the section titled,
Recapitulation). When you can remember the
explanations by looking at this list, then you can stop looking at it.
- Information
- types
- values
- variables
- expressions
- Language Elements
- classes
- variables
- methods
- constructors
- objects
- statements
- identifiers
- methods/messages
- signatures
- parameters (formal/actual)
- parameter linkages
- syntax
- semantics
- Process
- editing
- compilation
- execution
- debugging
- prototyping
Sample questions:
- Assume you have an int variable, x; write Java code to either sout "yes" or "no"
depending on whether x is more than 100.
- Assume you have an int variable, x; write Java code to sout "yes"if x is 17.
- Write a while loop that will output the numbers 1-10, one per line.
- Write a for loop that will output the numbers 1-10, all on the same line.
- Write a method, myFavoriteNumber, with no parameters, that returns 17.
- Write a method, theNewPresident, with no parameters, that returns "Obama!".
- Write a method, mySchoolIsWhitman, with no parameters, that returns false.
- Write a method, firstVowel, with no parameters, that returns 'e'.
- Write a method, twice, which returns double the value of its int parameter.
- Write a method, max, which returns the value of the larger of its two int parameters.
- Write a method, firstChar, with a String parameter, which returns the first character of its parameter.
- Write a method, secondChar, which returns the second character of its String parameter.
- 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, secondVowel, with a String parameter, which returns either the second vowel in the param, or '?' if
- Write a method, lastChar, with a String parameter, which returns the last character of its parameter.
- Write a method, longer, with two String parameters, which returns the longer of its parameters.
- Write a method, same, with two String parameters, which returns true if its parameters are equal (not ==!).
- Write a method, same, with three int parameters, which returns true if its parameters are all equal.
- Write a method, reverse, with a String parameter, which returns its parameter backwards.
- Write a method, countZs, with a String parameter, which returns the number of z's (upper and lowercase) in its parameter.
- Write a method, moreZs, with two String parameters, which returns whichever parameter has more z's.
- Write a method, mostZs, with an ArrayList<String> parameter, which returns whichever String in the list has the most z's.
- Write the more general versions of the previous three methods, which are passed a char additionally, and use that instead of z.
- Write a complete Student class including variables for name and
grade point average, accessors for each, toString(), and an initializing constructor.
- Write a complete Course class, which contains variables for the course name and the number of students enrolled
- Add 4 variables to Student, for the 4 classes they are currently enrolled in.
- Write a method that is passed two Students and returns the one with the higher GPA.
- Write a method that is passed two Students and returns the one that is in the biggest course.
- Write a method that is passed two Students and returns the one that has the most classmates (i.e. has the most
total students in their classes).
- Add a list of Students to each course (ArrayList<Student> would work well).
- Write a method that is passed two Students and returns the one that is enrolled in classes with the highest average
GPA.
- Write a method, sqrt, that is passed an int and returns its squareroot.
- Write a method, sqrt, that is passed an int and returns its squareroot without using Math.sqrt(). Hint use binary search.
i.e. if the parameter is n, guess n/2, then n/4, etc until the guess is too small, then work back up... Make sure your answer squared is within 0.01
of the parameter.