You will be given a sheet of standard methods you can refer to during the exam.
You can see a copy of this sheet
here.
Assignments
Lab 9 Due Beginning of Week 15
Project 3 Due
Final
Final Review Problems 1
Material to Review
For Java programming, review the labs, the projects, and the
activities from the lecture notes. Some of these will likely be
part of the exam.
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:
Reading
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
Supplement 3G
Everything
3-4
Chapter 4
Everything except System.out.printf
1-2, 5-7, 9, 16, 20, 26-27
Chapter 5
Everything except do/while
1-2, 4-5, 12-13, 14-15, 17, 23
Chapter 7
Everything except multidimensional arrays
2, 4-5, 9-10, 15-17, 19, 29
Note: All the Self-Check Problems are good to do. The above
selects a subset of them as examples of what to study.
Lists of Terminology, Notation, and Keywords
Terminology
Hover mouse for more information
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
array
holds multiple values of the same type
array element
a value in an array
array traversal
processing each array element in sequence
assignment statement
stores a value in a variable
cast
explicitly converting a value to a different type
class
a category or type of object
comment
text in a program for explaining code
compiler
a program that checks and translates a program
counter
variable that is incremented each time a test is true
cumulative algorithm
computes an overall value incrementally
data type
a name for a category of values
declaration
specifies a variable with a name and type
exception
a runtime error
expression
a value or a combination of operations that produce a value
fencepost loop
the first or last value requires special processing
flow of control
the order in which statements are executed
identifier
a name for a class, method, or variable
if statement
executes different statements depending on a test
index
a location in an array or String
index out of bounds
an illegal location, less than zero or beyond the end of an array or String
keyword
a word reserved for a particular use
loop
executes a group of statements repeatedly depending on a test
method
group of statements with a name
method call
a command to execute the statements in a method
object
an entity that contains state and behavior
operator
a symbol that indicates an operation to perform
parameter
a value passed to a method
precedence
the order in which operators are evaluated in an expression
procedural decomposition
separation of a task into subtasks
pseudocode
English-like description of an algorithm
reference
the location of an array or object
return type
the kind of value a method returns
scope
the part of a program where a declaration is valid
statement
a single command that can be executed
test
a boolean expression used to control statements
variable
a named location for storing a value
Notation
Hover mouse for more information
!
!=
" "
%
&&
' '
( )
*
*=
+
++
+=
,
-
--
-=
.
/
/* */
//
/=
;
<
<=
=
==
>
>=
[ ]
\"
\\
\n
\t
{ }
||
!
logical NOT
!=
not equal to
" "
contains a string
%
remainder (or mod) operator
&&
logical AND
' '
contains a char
( )
contains parameter
*
multiply operator
*=
multiply a variable times an expression
+
addition operator
++
increment a variable
+=
add an expression to a variable
,
separates parameters
-
subtraction operator
--
decrement a variable
-=
subtract an expression from a variable
.
call a method in another class
/
division operator
/* */
contains a comment
//
starts a comment
/=
divide a variable by an expression
;
ends a statement
<
less than
<=
less than or equal to
=
assignment operator
==
equal to
>
greater than
>=
greater than or equal to
[ ]
contains an array index
\"
escape sequence for "
\\
escape sequence for \
\n
escape sequence for a newline
\t
escape sequence for a tab
{ }
encloses a class or a group of statements
||
logical OR
Keywords
Hover mouse for more information
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
boolean
primitive type for true and false
char
primitive type for characters
double
primitive type for real numbers
else
indicates statements to execute when the test is false
equals
method for testing equality of objects
false
boolean value
final
used for declaring constants
for
a loop typically used to count from one number to another
if
indicates a test and statements to execute when the test is true
import
use a Java package
int
a primitive type for integers
main
the method that starts a Java program
new
constructs a new object or array
null
a value that means "no object"
println
method for printing output
public class
phrase for beginning a class
public static
phrase for beginning a method
return
indicates value to send back to method call
true
a boolean value
void
indicates that no value is returned
while
repeat a group of statements as long as a test is true
Graphics
a class for drawing on windows
Math
a class with static methods for common math operations
Random
a class for generating pseudorandom numbers
Scanner
a class for reading input
String
a class for manipulating strings
Final Review Problems 2
Final Review Problems 3
Additional Activities
Activity: Draw Red and Blue Circles
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).
Activity: Three Doubles Mehtods
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 16 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.
Activity: Determine Data Type
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. 345.]
Activity: StringAgain
Write a Java program that inputs Strings from the user until the user
enters the first String again.
Answer:
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();
}
}
}
What will be the difference if the nextLine method is used
instead of the next method?
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.
Activty: Divisible by 2
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.]
Activty: Double Array Methods
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. 450.]
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
10 in Chapter 7.]
Increment every element in the array. [See p. 454 and p. 477.]
Replace negative elements with zeroes.
Return the number of elements that are negative.
Return true if every element is negative.
Answer:
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);
}
This code serves as a hint for the previous and next tasks in this list.
Return true if most of the elements are negative.
Activity: Self Check 29
This is based on Self-Check Problem 29 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.