Quiz questions/Answers.
Latest update: Nov 18, 2004
Exam 1 statistics: Average: 75.3. Max: 99.
Exam 2 statistics: Avg. 64.7. Max: 99.
Project 1 statistics: Average: 4.3. Max: 5. Min: 3.
Project 2 statistics: Average: 3.5. Max: 5. Min: 1 (All but 2 groups submitted early and received 10% extra credit.)
Project 3 statistics: Average: 4.81. Max 5.4. Low: 4.2.
Quiz date | Question | Answer | Statistics (# of Correct/Incorrect answers) | ||||||
8/25 | What is an applet? | A Java program usually executed from within a browser. (A more detailed and accurate answer will be given after the first two weeks.) | 48/15 | ||||||
8/30 | Declare a button labeled "Purdue". | Button purdueButton=new Button("Purdue"); | 46/16 | ||||||
9/1 | Describe in one sentence the difference between a class and an object. | A class is a collection of data and methods; it serves as a template for creating objects. | 53/11 | ||||||
9/8 | Write a Java statement to do the following: Invoke method playSound() when the value of variable count is greater than or equal to 99. | if (count >= 99)
{ playSound(); } |
52/10 | ||||||
9/15 | myDog is an object of type Dog. setName(String s) is a method used to set the name of a Dog object to string s. Write a Java statement to set the name of myDog to "ChiChi". | myDog.setName("ChiChi"); | 38/21 | ||||||
9/20 | int v=10;
TextField t=new TextField(5); Write Java code to display the value of v into the textfield t. |
String vString=Integer.toString(v);
t.setText(vString); |
39/17 | ||||||
9/22 | boolean done;
int count; Set count to -1 if done is true else set it to 1. |
if (done)
{ count=-1; } else { count=1; } |
45/13 | ||||||
9/27 | Describe in one sentence when to use each type of loop (for, do-while, while) . | for: when we know how many times the loop body is to be executed.
do-while: when the loop body must be executed at least once. while: when the loop body is to be executed 0 or more times and we do not know how many times it is to be executed. |
34/10 | ||||||
9/29 | Given the following data: 93.173, 21.11, 7.907, 39.71, declare and initialize an array. | double nums[]={93.173, 21.11, 7.907, 39.71}; | 32/22 | ||||||
10/4 | Declare an array named answers and initialize it with values true, false, and true. | boolean [ ] answers={true, false, true}; | 14/43 | ||||||
10/6 | int sum=0; int num=5;
while (num<=20){ ------ ------ } Write two statements in the loop body that will cause the loop to find the sum of integers numbers from 5 to 20 (inclusive). |
sum=sum+num;
num++; |
26/27 | ||||||
10/13 | Given:
boolean done; int index; int [] data=new int[20]; if ( ...){ .... } else{ ... } Fill in the blanks (...) so that the code segment sets done to true if data[index] is 0 else set done to fale. |
if ( data[index]==0){ done=true; } else{ done=false; } |
26/26 | ||||||
10/18 | Add a loop to the code shown below so that all elements of the protein array are initialized to the string "Empty".
String [ ] protein=new String [20]; protien[index]="Empty"; |
String [ ] protein=new String [20]; for (int index=0; index<20; index++) protein[index]="Empty"; alternately... for (int index=0; index<protein.length; index++) protein[index]="Empty"; |
35/12 | ||||||
10/20 | Button [] b=new Button [20]
for (int i=0; i<20; i++){ --- } Fill in the blank by adding one statement so that 20 buttons are created and each labeled "Hello". |
utton [] b=new Button [20]
for (int i=0; i<20; i++){ b[i]=new Button("Hello"); } |
13/25 | ||||||
10/25 | What is the value of p when the loop terminates?
int [ ] data={5, 3, 0, 4}; int p=1; int index=0; while(index<data.length || data[index]!=0){ p=p*data[index]; index++; } |
0 | 39/7 | ||||||
11/1 | int [] data=new int [20];
int [] sum=new int [20] for (int i=0;i<data.lngth; i++{ for(intj=0; j<=i;j++){ ....... } } Add code to the skeleton above to fill the summ array such that sum[i] contains the sum of all inteegers from data[0] to data[i]. |
int [] data=new int [20];
int [] sum=new int [20] for (int i=0;i<data.lngth; i++{ sum[i]=0; for(intj=0; j<=i;j++){ sum[i]=sum[i]+data[j]; } } |
10//29 | ||||||
11/3 | Double Quiz on 11/3!
Q1: Declare gLayout as an object of type GridLayout to correspond to the following grid. |
Q1.
GridLayout gLayout=new GridLayout (2, 3); |
Q1: 38/1 | ||||||
11/3 |
Q2. Button aButton=new Button(); Button bButton=new Button(); BorderLayout bLayout=new BorderLayout(); ... this.setLayout(bLayout); Write Java statements to add aButton to the center and bButton to the North of the conatiner. |
Q2.add(BorderLayout.CENTER, aButton); add(BorderLayout.NORTH, bButton); Notice that CENTER and NORTH are in caps. |
Q2: 24/15 | ||||||
11/8 | String s=new String("");
char [] c= new char [20]; Write a Java statement that will convert characters in the c array to a string assigned to s. |
s=new String(c); | 11/33 | ||||||
11/10 | String s=new String (" ");
char c; Write a loop that extracts characters from s and assigns each character to c. There is no further processing required with c. |
for (int i=0; i<s.length; i++){
c=charAt(i); } |
24/10 | ||||||
11/15 | int sum=88;
for(int i=3; i<=5; i++){ sum=sum+i; } What is the value of sum when the loop terminates? |
100 | 34/1 | ||||||
11/17 | String s="Hello";
int j=5; for(int i=0; i<5; i++){ char c=s.charAt(j-i-1); j--; } What are the successive values of c? |
Successive values of c are: 'o', 'l', and 'H'.
A "String index out of bounds " exception will be raised when the index (j-i-1) becomes negative. |
21/13 |