Do Not Remove Staples! (5) Name:______

Spring 2000 ISQS 6337 Exam 1

1.  Use an application to create a switch statement that displays a message on the system console for each case (use only case values of 10, 8, and 6). Put the switch inside a for loop that tries each case. Write all the code necessary (package, import, class, etc) ` (20)

2. Show the output of the above application after removing all break statements. (5)

3. Write a JApplet that displays: (20)

  1. “Hello World” on the system console ONLY when it is loaded
  2. “TTFN” on the system console ONLY when the applet is minimized
  3. “Hello Again” on the system console ONLY when the applet is restored
  4. “Good Bye” on the system console ONLY when the applet is closed


Use Code Segment A to answer questions 4 - 8

4. Write the code necessary to call MethodOne from S00_Exam1.main() (3)

5. Write the code necessary to call MethodOne from any other class (4)

6. What is the purpose of the int in the header for MethodOne() above? (3)

7. What is the purpose of String s in the header for prt above? (3)

8. What is the output of MethodOne()? (20)

Use Code Segment B to answer questions 9 – 10

9. What is the code necessary to initialize the reference sName? (3)

10.  Once it is initialized what are two methods available using sName? (5)

11.  Write the code necessary to determine whether or not the value of iCol is evenly divisible by 7. (3)

12.  Write the code necessary to increment the value of iCol by 2. (1)

13.  Write the code necessary to determine if the third letter in sName is a digit. (5)


// CODE SEGMENT A:

// part of class S00_Exam1

public static int MethodOne() {

int i = 0;

outer:

while (true) {

prt("Outer while loop");

while (true) {

i++;

prt("i = " + i);

if (i == 1) {

prt("continue");

continue;

}

if (i == 3) {

prt("continue outer");

continue outer;

}

if (i == 5) {

prt("break");

break;

}

if (i == 7) {

prt("break outer");

break outer;

}

}

}

return 0;

}

static void prt(String s) {

System.out.println(s); // displays s on the system console

}

// CODE SEGMENT B:

// part of class S00_Exam1

public static int MethodTwo() {

String sName;

System.out.println(sName); // displays sName on system console

int iCol = 0;

// assume the value of iCol is changed in some way here

}