Week 10: Exam 2 Review
- Project 2 Due beginning of Week 10
- Exam 2
Material to Review
For Java programming, review your labs, your Projects 1 and 2, and the
activities from the lecture notes. Some of these will likely be
part of the exam.
For general knowledge, review Chapters 1-4, Supplement 3G, your
quizzes, and the lecture notes. Understanding the chapter
summaries and self-check problems is a good way to start reviewing
the book material. Below is a table of particular items to pay
|| Chapter Summary
|| Self-Check Problems
|Chapter 1 ||Everything ||6, 9, 12, 14, 16, 18-19, 22-25
|Chapter 2 ||Everything ||1-2, 6-7, 11-12, 16, 19-20, 23, 26-27, 32
|Chapter 3 ||Everything
||5-6, 10, 13-14, 16, 20-21, 24, 26
|Chapter 4 ||Everything except System.out.printf
||1-2, 5-7, 9, 16, 20, 26-27
Note: All the Self-Check Problems are good to do. The above selects a subset of them as examples of what to study.
The terminology, notation, and keywords below are in addition to the
lists in the Exam 1 Review.
Write a method that has three integer parameters
and returns the minimum value. Write one version using
Math.min. [See Self-Check Problem 16 in Chapter 3.]
Write another version using a nested if statement.
Write a method that has three integer parameters and returns the
median (middle) value. [See Self-Check Problem 27 in Chapter 4.]
Write a method that has two parameters, a Scanner and
a String, and returns an int. The method should
use the String to prompt the user and use
the Scanner to input the value. That is, we want to
replace this code:
System.out.print("Enter your most favorite integer: ");
int mostFavorite = console.nextInt();
System.out.print("Enter your least favorite integer: ");
int leastFavorite = console.nextInt();
Write two other methods, one for inputting a double and the
other for inputting a String. Write a Java program for
testing your methods.
int mostFavorite = getInt(console, "Enter your most favorite integer: ");
int leastFavorite = getInt(console, "Enter your least favorite integer: ");
Modify the drawDiamond method on p. 213 so that
it includes parameters for the width and the height of the box.
For example, the following code:
should produce the following output:
DrawingPanel panel = new DrawingPanel(600,400);
Graphics g = panel.getGraphics();
drawDiamond(g, 50, 50, 100, 300);
drawDiamond(g, 150, 50, 300, 150);
drawDiamond(g, 150, 200, 300, 150);
drawDiamond(g, 450, 50, 100, 300);
Hints: Each 50 in the drawDiamonds method needs to be replaced
with either the width or height as appropriate.
Each 25 in the drawDiamonds method needs to be replaced
with either width divided by 2 or height divided by 2.
Create modified versions of the
countLetters method on pp. 264-265 to
perform the following tasks.
Write a Java program that inputs lines from the user and prints
the results of these methods for each line.
- Count the number of lower case letters.
- Count the number of digits.
- Count the number of digits and letters.
- Count the number of blanks.
Write a Java program to input 10 doubles from the user
and print the minimum. Hint: Modify the MaxInput program in
the lecture notes.
Now modify your program so it also prints the maximum and the average.