Do Not Remove Staples! (5) Name:______
Spring 2001 ISQS 6337 Exam 1
All code segments can be found at the end of the test. If you want feel free to detach ONLY THOSE PAGES!
- Write the html applet tag necessary to run applet from Code Segment A (5)
- Assuming that the code in Code Segment A is compiled and the class files are put in: (5)
c:\java-Projects\s01_exam1\classes\s01_exam1
where must the html file be put for the applet to run correctly? - What is the output from the applet in Code Segment A if I: (10)
run the applet, minimize the applet, maximize the applet, and close the applet?
- Write an application that first prompts the user for an integer, second fills an integer array with the 15 numbers following, the user input number that are evenly divisible by 3, and finally prints out the sum of all 15 elements in the array. All of the code necessary to accomplish this may be in the main method EXCEPT the sum code. You must write a method that takes the integer array as an argument and returns the sum of its elements. (30)
Use Code Segment C to answer questions 5 - 9
- Write the minimum code necessary to call MethodOne from Exam1_CodeSegment_C.main() (5)
- Write the minumum code necessary to call MethodOne from any other class (5)
- What is the effect of the static modifier in the header for MethodOne() ? (5)
- Assuming that fTest is used to call MethodOne. What is the value of fTest after the call to MethodOne in Exam1_CodeSegment_C.main() ? (5)
- What is the output of MethodOne()? (10)
- What is difference between an object and a class? (5)
- What is the output of running Application1 in Code Segment B (15)
// CODE SEGMENT A
package s01_exam1;
import java.awt.*;
import javax.swing.*;
public class Exam1_CodeSegment_A extends JApplet {
public Exam1_CodeSegment_A() { System.out.println("constructor");}
public void init() { System.out.println("init"); }
public void start() { System.out.println("start"); }
public void stop() { System.out.println("stop"); }
public void destroy() { System.out.println("destroy"); }
public void paint(Graphics g) { System.out.println("paint"); }
}
------
// CODE SEGMENT B:
public class Application1 {
/**Construct the Application*/
public Application1() {
s01_Exam1_Code_Section_B classRef = new s01_Exam1_Code_Section_B("John");
System.out.println(classRef.sName);
MethodTwo(classRef);
System.out.println(classRef.sName);
MethodThree(classRef);
System.out.println(classRef.sName);
}
/**Main method*/
public static void main(String[] args) {
Application1 App = new Application1();
}
public void MethodTwo(s01_Exam1_Code_Section_B xRef) {
xRef = new s01_Exam1_Code_Section_B("Bob");
}
public void MethodThree(s01_Exam1_Code_Section_B yRef) {
yRef.sName = "Sean";
}
}
class s01_Exam1_Code_Section_B {
public String sName;
public s01_Exam1_Code_Section_B(String s) { sName = s; }
}
// CODE SEGMENT C:
package s01_exam1; // line 2
import javax.swing.*; // line 4
public class Exam1_CodeSegment_C { // line 6
public static void main(String[] args) {
double fTest = 1.111;
// call to line 14 goes here // line 10
System.exit(0);
}
public static int MethodOne(double fSomeNumber) { // line 14
fSomeNumber *= 3;
int i = 1;
outer:
while (true) {
prt("Outer while loop");
do {
System.out.println(i++);
if (i == 1)
break;
if (i == 3)
continue outer;
if (i == 5 & i++ < 10)
break outer;
} while (i < 5);
}
return i;
}
static void prt(String s) { // line 41
System.out.println(s); // displays s on the system console
}
}