![Fall 99 ISQS 6337 Exam 1](https://data.docslib.org/img/3a60ab92a6e30910dab9bd827208bcff-1.webp)
<p> Spring 2004 ISQS 6337 Exam 1</p><p>1. Explain the difference between: (5)</p><p>BankAccount b; and BankAccount b = new BankAccount(5000);</p><p> the first creates a reference to a BankAccount class but does not instantiate an object the second creates the reference and instantiates the BankAccount object</p><p>2. Write a method that takes in an array of integers (as int's) and returns the smallest in the group. (15)</p><p> see question 5</p><p>3. What methods in an Applet, or in a JApplet, are called ONLY when the program first starts? (5)</p><p>The constructor & init()</p><p>4. What is printed given the following code? (5) int x = 15; System.out.println((x%2 == 0) ? "Even" : "Odd");</p><p>Odd 5. Write an application that reads in five integers and determines and prints the largest and the smallest in the group. (20)</p><p>//Something like import javax.swing.JOptionPane; public class Ex1_Q5 {</p><p>//Main method public static void main(String[] args) { int[] iaNumbers = new int[5]; int iLow, iHigh;</p><p> for (int i = 0; i<5; i++) { iaNumbers[i] = Integer.parseInt( JOptionPane.showInputDialog("Enter an integer please")); } iLow = getLowest(iaNumbers); iHigh = getHighest(iaNumbers);</p><p>System.out.println("Low = " + iLow + "\nHigh = " +iHigh); } // end of main public static int getLowest(int[] a) { int iCurrent = a[0];</p><p> for (int i = 1; i < a.length; i++) if (a[i] < iCurrent) iCurrent = a[i];</p><p> return iCurrent; } // end of getLowest public static int getHighest(int[] a) { int iCurrent = a[0];</p><p> for (int i = 1; i < a.length; i++) if (a[i] > iCurrent) iCurrent = a[i];</p><p> return iCurrent; } // end of getHighest</p><p>} // end of class</p><p>6. Write the code to create a class called square. The class has: (20) a. only one attribute, width, that is an int b. a default constructor that creates a square with a width of 0 c. a one argument constructor that takes width as an argument d. a single method that returns the area of the square public class square { private int _width;</p><p> public square() { _width = 0; }</p><p> public square (int w) { _width = w; }</p><p> public int getWidth() { return _width; }</p><p> public void setWidth(int w) { _width = w; }</p><p> public int getArea() { return _width * _width; } }</p><p>7. Write the code to instantiate a square with a width of 150 and to print out it's area. (10)</p><p> square s = new square(150); System.out.println(s.getArea());</p><p>8. What does the following program sequence do? (10) for (int i = 1; i <= 2; i++) { for(int j = 1; j <= 3; j++) { for(int k=1;k%10 > 0;k++) System.out.print('*'); System.out.println(); } System.out.println(); } ********* ********* *********</p><p>********* ********* *********</p><p>9. What does the following code do? (10) int i = 5; while (i >= 0) { switch (i) { case 5: System.out.print("F "); case 4: System.out.print("E "); case 3: System.out.print("D "); case 2: System.out.print("C "); case 1: System.out.print("B "); default: System.out.print("A "); } System.out.print(); i--; }</p><p>F E D C B A E D C B A D C B A C B A B A A </p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages4 Page
-
File Size-