MIS-B310 Spring 2000                                                          Name ________________________

Final Exam                                                                             version #4                           (100 pts.)

 

24 pts.
this sect.

Correct that code (12 questions).  There is one type of error in each problem. Mark up the code clearly to indicate corrections, or rewrite the code with corrections. Assume that the rest of the program is complete and correct. The wide spacing is for your convenience in adding/correcting the code.

 

(2)

1.             int number;

      number = Integer.parseInt (

                    JOptionPane.showInputDialog (“Input a number” );  

 

 

(2)

2.             if ( a > b || b < c )

           JOptionPane.showMessageDialog ( b + “ is too low” );

 

 

(2)

3.             do {

           b = a * 3;

           a++;

      while ( a < 6 );

 

          

(2)

4.             g.drawString ( “The point is here” );

 

 

(2)

5.             for ( j = 0 ; j < 15 ; j++ )

            System.out.println ( j );

 

 

(2)

6.             String input,

      double number;

 

 

(2)

7.             tops = Math.max ( x , y , z );

 

 

(2)

8.             int guessIt ( int a )
      {
            return Math.random() * a + 1;

      }

 

(2)

9.             public int nextOne ( int x , y )
      {

            return x + 1 ;
      }

 

(2)

10.                int list [] = new list [ 6 ];

 

 

(2)

11.                double list [] = { 2 }{ 4 }{ 6 }{ 8 }{ 10 };

 

 

(2)

12.                int twoWay [ 3 ][ 4 ] = new int [ 3 ][ 4 ];

 


 

40 pts
this sect.

Create that code (8 questions)

 

(5)

13.          Write lines of code to compare three int-type variables: r, s, and t. Display the smallest of the three values (not the name of the variable) in the MS-DOS window. Assume that the variables have already been declared and initialized.

 

 

 

 

 

(5)

14.          Write a single line of code to generate a random integer in the range from 10 to (and including) 19. Assign the generated value to an already-declared variable named m.

 

 

 

 

(5)

15.          Write a line of code that calls to a method named checkIt using the number 1 and the string “correct” as arguments. The method checkIt returns an int-type value. Assign the returned value to an already-declared int-type variable called k.

 

 

 

 

(5)

16.          Define a method called tryIt that takes in two double-type values and returns the integer –1 if the sum of the two values is greater than 10, but returns the integer 0 otherwise.

 

 

 

 

(5)

17.          Define a method called plusOne that takes in an int-type value and a double-type value. It returns an int-type version of the product of the two inputs.

 

 

 

 

 

(5)

18.          Declare and allocate an array called pie with 10 positions. Using a for loop, fill the array positions with the integers from 11 to 20.

 

 

 

(5)

19.          Declare and allocate a multiple-subscripted array that represents a table with 5 columns and 2 rows. Name the array pasta.

 

 

 

 

(5)

20.          Declare and initialize a multiple-subscripted array that represents the following table:

1  3  5  7
2  4  6  8
3  5  7  9

 

 


36 pts.
this sect.

What's my output? (3 questions)  Draw a detailed sketch of what the output of each program would look like, given the information supplied.

(12)

//test question 21 for final exam

import javax.swing.*;

 

public class TestQ1 {

   public static void main ( String args[] )

   {

      int input;

      int sum;

 

      input = Integer.parseInt (

                   JOptionPane.showInputDialog ( "Number, please." ) );

 

      for ( int i = 1 ; i < input ; i++ ) {

         System.out.print( i * 5 + "-" );

 

         switch ( i ) {

            case 1:

               System.out.println();

               break;

            case 2:

               System.out.println( "*" );

               break;

            default:

               System.out.println( "?" );

         }

      }

   }

}


Assuming that the number 5  was typed in by the user at the appropriate time, what would appear in the   MS-DOS window? Draw a specific and detailed rendition.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



1

 
(12)

//test question 22 for final exam

import javax.swing.*;

 

public class TestQ2 extends JApplet {

   public void init ()

   {

      int input;

      String typed;

      String blah = "";

 

      typed = JOptionPane.showInputDialog ( "Number, please." );

      input = Integer.parseInt ( typed );

 

      int result = mysteryMethod ( input );

      blah += " is the result";

 

      JOptionPane.showMessageDialog ( null , result + blah );

 

      System.exit( 0 );

   }

 

   public int mysteryMethod ( int a )

   {

      if ( a <= 10 && a >= 4 )

         return a * 4;

      else

         return a * 3;

   }

}


Assuming that the number 4 was typed in by the user in that order at the appropriate times, what would the Message Dialog box look like? Draw a specific and detailed rendition.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(12)

//test question 23 for final exam

 

public class Lists {

   public static void main ( String args[] )

   {

      double g[] = new double [ 8 ];

 

      for ( int i = 0 ; i < g.length ; i++ ) {

         g [ i ] = i * 3 - ( i + 1.5 );

         System.out.println ( g [ i ] );

      }

     

      System.out.println();

 

      for ( int i = 3 ; i < g.length ; i++ )

         System.out.println ( g [ i ] );

 

      System.exit ( 0 );

   }

}

 


What would be displayed in the MS-DOS window? Draw a specific and detailed rendition.


1