- •Cover Page
- •Java Programming: Contents
- •Java Programming: Preface to the Third Edition
- •Java Programming: Preface to Previous Edition
- •Java Programing: Chapter 1
- •Java Programing: Section 1.1
- •Java Programing: Section 1.2
- •Java Programing: Section 1.3
- •Java Programing: Section 1.4
- •Java Programing: Section 1.5
- •Java Programing: Section 1.6
- •Java Programing: Section 1.7
- •Java Programing: Chapter 1 Quiz
- •Java Programing: Chapter 2 Index
- •Java Programing: Section 2.1
- •Java Programing: Section 2.2
- •Java Programing: Section 2.3
- •Java Programing: Section 2.4
- •Java Programing: Section 2.5
- •Java Programing: Chapter 2 Exercises
- •Java Programing: Chapter 2 Quiz
- •Java Programing: Chapter 3 Index
- •Java Programing: Section 3.1
- •Java Programing: Section 3.2
- •Java Programing: Section 3.3
- •Java Programing: Section 3.4
- •Java Programing: Section 3.5
- •Java Programing: Section 3.6
- •Java Programing: Section 3.7
- •Java Programing: Chapter 3 Exercises
- •Java Programing: Chapter 3 Quiz
- •Java Programing: Chapter 4 Index
- •Java Programing: Section 4.1
- •Java Programing: Section 4.2
- •Java Programing: Section 4.3
- •Java Programing: Section 4.4
- •Java Programing: Section 4.5
- •Java Programing: Section 4.6
- •Java Programing: Section 4.7
- •Java Programing: Chapter 4 Exercises
- •Java Programing: Chapter 4 Quiz
- •Java Programing: Chapter 5 Index
- •Java Programing: Section 5.1
- •Java Programing: Section 5.2
- •Java Programing: Section 5.3
- •Java Programing: Section 5.4
- •Java Programing: Section 5.5
- •Java Programing: Chapter 5 Exercises
- •Java Programing: Chapter 5 Quiz
- •Java Programing: Chapter 6 Index
- •Java Programing: Section 6.1
- •Java Programing: Section 6.2
- •Java Programing: Section 6.3
- •Java Programing: Section 6.4
- •Java Programing: Section 6.5
- •Java Programing: Section 6.6
- •Java Programing: Section 6.7
- •Java Programing: Chapter 6 Exercises
- •Java Programing: Chapter 6 Quiz
- •Java Programing: Chapter 7 Index
- •Java Programing: Section 7.1
- •Java Programing: Section 7.2
- •Java Programing: Section 7.3
- •Java Programing: Section 7.4
- •Java Programing: Section 7.5
- •Java Programing: Section 7.6
- •Java Programing: Section 7.7
- •Java Programing: Section 7.8
- •Java Programing: Chapter 7 Exercises
- •Java Programing: Chapter 7 Quiz
- •Java Programing: Chapter 8 Index
- •Java Programing: Section 8.1
- •Java Programing: Section 8.2
- •Java Programing: Section 8.3
- •Java Programing: Section 8.4
- •Java Programing: Section 8.5
- •Java Programing: Chapter 8 Exercises
- •Java Programing: Chapter 8 Quiz
- •Java Programing: Chapter 9 Index
- •Java Programing: Section 9.1
- •Java Programing: Section 9.2
- •Java Programing: Section 9.3
- •Java Programing: Section 9.4
- •Java Programing: Chapter 9 Exercises
- •Java Programing: Chapter 9 Quiz
- •Java Programing: Chapter 10 Index
- •Java Programing: Section 10.1
- •Java Programing: Section 10.2
- •Java Programing: Section 10.3
- •Java Programing: Section 10.4
- •Java Programing: Section 10.5
- •Java Programing: Chapter 10 Exercises
- •Java Programing: Chapter 10 Quiz
- •Java Programing: Chapter 11 Index
- •Java Programing: Section 11.1
- •Java Programing: Section 11.2
- •Java Programing: Section 11.3
- •Java Programing: Section 11.4
- •Java Programing: Section 11.5
- •Java Programming, Chapter 11 Exercises
- •Java Programming, Chapter 11 Quiz
- •Java Programing: Appendix 1 Index
- •Java Programing: Appendix 1, Section 1
- •Java Programing: Appendix 1, Section 2
- •Java Programing: Appendix 1, Section 3
- •Some Notes on Java Programming Environments
Java Programing: Chapter 8 Quiz
Quiz Questions
For Chapter 8
THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 8 of this on-line Java textbook. You
should be able to answer these questions after studying that chapter. Sample answers to all the quiz questions can be found here.
Question 1: What does the computer do when it executes the following statement? Try to give as complete an answer as possible.
Color[] pallette = new Color[12];
Question 2: What is meant by the basetype of an array?
Question 3: What does it mean to sort an array?
Question 4: What is meant by a dynamic array? What is the advantage of a dynamic array over a regular array?
Question 5: What is the purpose of the following subroutine? What is the meaning of the value that it returns, in terms of the value of its parameter?
static String concat( String[] str ) { if (str == null)
return null; String ans = "";
for (int i = 0; i < str.length; i++) { ans = ans + str[i];
return ans;
}
Question 6: Show the exact output produced by the following code segment.
char[][] pic = new char[6][6]; for (int i = 0; i < 6; i++)
for (int j = 0; j < 6; j++) {
if ( i == j || i == 0 || i == 5 ) pic[i][j] = '*';
else
pic[i][j] = '.';
}
for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++)
System.out.println(pic[i][j]);
System.out.println();
}
Question 7: Write a complete subroutine that finds the largest value in an array of ints. The subroutine should have one parameter, which is an array of type int[]. The largest number in the array should be returned as the value of the subroutine.
Question 8: Suppose that temperature measurements were made on each day of 1999 in each of 100 cities. The measurements have been stored in an array
int[][] temps = new int[100][365];
http://math.hws.edu/javanotes/c8/quiz.html (1 of 2) [5/24/2000 8:39:34 AM]
Java Programing: Chapter 8 Quiz
where temps[c][d] holds the measurement for city number c on the dth day of the year. Write a code segment that will print out the average temperature, over the course of the whole year, for each city. The average temperature for a city can be obtained by adding up all 365 measurements for that city and dividing the answer by 365.0.
Question 9: Suppose that a class, Employee, is defined as follows:
class Employee { String lastName; String firstName; double hourlyWage;
int yearsWithCompany;
}
Suppose that data about 100 employees is already stored in an array:
Employee[] employeeData = new Employee[100];
Write a code segment that will output the first name, last name, and hourly wage of each employee who has been with the company for 20 years or more.
Question 10: Suppose that A has been declared and initialized with the statement
double[] A = new double[20];
And suppose that A has already been filled with 20 values. Write a program segment that will find the average of all the non-zero numbers in the array. (The average is the sum of the numbers, divided by the number of numbers. Note that you will have to count the number of non-zero entries in the array.) Declare any variables that you use.
[ Answers | Chapter Index | Main Index ]
http://math.hws.edu/javanotes/c8/quiz.html (2 of 2) [5/24/2000 8:39:34 AM]
