For general knowledge, review Chapters 1-5, Sections 7.1-7.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 attention to:
Note: All the Self-Check Problems are good to do. The above selects a subset of them as examples of what to study.
Reading Chapter Summary Self-Check Problems Chapter 1 Everything 6, 8, 11, 13, 15-17, 19-21 Chapter 2 Everything 1-2, 6-7, 11-12, 14-15, 21, 27 Chapter 3 Everything 2-3, 7, 10-12, 14-15, 18-19 Supplement 3G Everything 2-3 Chapter 4 Everything except System.out.printf 1-5, 7, 13, 17, 23-24 Chapter 5 Everything except do/while 1-2, 4-5, 12-13, 14-15, 17, 23 Chapter 7 Everything except multidimensional arrays 1, 3-4, 6-7, 11-13, 15, 25
array array element array traversal assignment statement cast class comment compiler counter cumulative algorithm data type declaration
exception expression fencepost loop flow of control identifier if statement index index out of bounds keyword loop method method call
object operator parameter precedence procedural decomposition pseudocode reference return type scope statement test variable
! != " " % && ' ' ( )
* *= + ++ += , -
-- -= . / /* */ // /=
; < <= = == > >=
[ ] \" \\ \n \t { } ||
boolean char double else equals false final
for if import int main new null
println public class public static return true void while
Graphics Math Random Scanner String
Write a Java program that draws the following pattern on a DrawingPanel: Hint: Draw blue circles centered at (0,0) and red circles centered at (300,0).![]()
Write a Java program that inputs three doubles from the user. Write and test methods for one or more of the following tasks.
- Return the mininum of the three numbers. Write one version using Math.min and another version using if statements. [See Self-Check Problem 12 in Chapter 3.]
- Return the median of the three numbers.
- Return true if all three numbers are equal to each other.
- Return true if all three numbers are different from each other.
- Return true if two of the three numbers are negative.
Write a Java program that inputs a token from the user and determines whether the user entered an int, double, or a String. Hint: Use the hasNextInt and hasNextDouble methods of Scanner. [See the ExamineInput1 program on p. 335.]
Write a Java program that inputs Strings from the user until the user enters the first String again. Answer:
What will be the difference if the nextLine method is used instead of the next method?import java.util.*; public class StringAgain { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Enter the first string:"); String first = console.next(); String next = ""; // priming the loop while (! first.equals(next)) { System.out.print("Enter the next string:"); next = console.next(); } } }Some variations on this task include:
- Write a Java program that inputs Strings from the user until the user enters a different String.
- Write a Java program that inputs Strings from the user until the user enters a String that contains a 'z'.
- Write a Java program that inputs Strings from the user until the user enters the same String twice in a row.
Write a Java program that inputs an int from the user and determines how many times the number is divisible by 2. The program should keep dividing the number by 2 until the number is odd. [See Self-Check Problem 4 in Chapter 5.]
Write a Java program to input doubles from the user for an array. First ask the user how long the array should be. [See the Temperature2 program on p. 436.] Write and test methods for one or more of the following tasks.
- Return the sum of the array.
Answer:
public static double sumArray(double[] list) { double sum = 0; for (int i = 0; i < list.length; i++) { sum += list[i]; } return sum; }
- Return the maximum element of the array. [See Self-Check Problem 7 in Chapter 7.]
- Increment every element in the array. [See p. 440 and p. 463.]
- Replace negative elements with zeroes.
- Return the number of elements that are negative.
- Return true if every element is negative.
Answer:
This code serves as a hint for the previous and next tasks in this list.public static boolean allNegative(double[] data) { int count = 0; for (int i = 0; i < data.length; i++) { if (data[i] < 0) { count++; } } return (count == data.length); }
- Return true if most of the elements are negative.
This is based on Self-Check Problem 25 in Chapter 7. Write a method that computes the average String length of an array of Strings. For example, the array {"Write", "a", "method", "in", "Java"} has an average length of 3.6. Write a Java program that tests your method.