WARNING: THIS WILL PROBABLY NOT PRINT CORRECTLY USING NETSCAPE -- USE INTERNET EXPLORER TO PRINT THIS OUT.

MIS-B310                                                                           Name __________________

Midterm Exam                                                               version #1        (100 pts.)

 

Correct that code (10 questions – 3 points each).  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.

 

1.             JOptionPane.showMessageDialog ( null , c “\n” c++ );

 

2.             JOptionPane.showMessageDialog ( null , " Greetings " ,
           JOptionPane.PLAIN_MESSAGE ) ;

 

3.             g.drawRect ( 20 ; 40 ; 60 ; 80 ) ;

 

4.             String y ;
      int x ;


      y = Integer.parseInt ( x );

5.             if   (   george   <=   50   ) {

      System.out.print (  " George is " ) ;

      System.out.println  (  "not over 50  " ) ;
      }

 

      else  (  george > 50 )

            System.out.println  (  " George is over 50." ) ;

 

6.             int number ,
      String input ;

 

7.             JOptionPane.showMessageDialog ( null , “It is now “ ++x ) ;

 

8.             while ( x != 999 )

         result = “you’re alive” ;
         JOptionPane.showMessageDialog ( null , result );
         xString = JOptionPane.showInputDialog ( “age? 999 to exit“ );
         x = Double.parseDouble ( xString );

 

9.             while ( x < 5 ) {
             x+ ;

             result = result + “*” ;

      }

 

10.                double c == 4.52 ;

System.out.print ( c + “ is the answer” ) ;

 

 


 

Create that code (6 questions – 6 points each)

 

7.       Write a single statement that will show a MessageDialog box displaying the value of an integer variable x. The Message Dialog box should have the “warning” icon and the text in the title bar “Your value”.

 

 





8.       Use a while loop to print a row of ten exclamation marks in the MS-DOS window. Declare & initialize any variables you will use.




 




9.       Create lines of code to declare and initialize a double-type variable called var1. Initialize var1 to zero.


 




10.    Create a single statement that will do two things: 1) add 1 to an int-type variable called blue before 2) printing out a Message Dialog box that will display the value of blue. Assume that blue has already been declared and initialized.

 

 

 



11.    Create lines of code that will print the greater of two inputs, x & y. Assume that the inputs have already been parsed from Input Dialog boxes as int-type variables.

 

 

 

 



12.    Create lines of code that will print out the phrase “Sorry!” in the MS-DOS window ONLY if a double-type variable named number is less than 0. Assume that number has already been declared and initialized.


 

 

 

 

 

 


 


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

//test question 10 for 2nd quiz

 

import javax.swing.JApplet;
import javax.swing.JOptionPane;

import java.awt.Graphics;

 

public class WhoKnows extends JApplet {

   int var1;

 

   public void init ()

   {

      String input;

     

      JOptionPane.showMessageDialog ( null , "A little program" );

      Input = JOptionPane.showInputDialog("Pick a number: 1 <-> 10" );

 

      var1 = Integer.parseInt ( input );

   }

 

   public void paint ( Graphics g )

   {

      if ( var1 < 3 )     

         g.drawRect ( 15 , 15 , 20 , 80 );

      else if ( var1 < 6 )

         g.drawString ( "In the middle" , 20 , 20 );

      else

         g.drawRect ( 40 , 40 , 60 , 20 );

   }

}

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




















 

//test question 11 for quiz 2

 

import javax.swing.*;

 

public class NextQuestion {

   public static void main ( String args[] )

   {

     String input1, input2, input3;

     int num1, num2, num3, largest;

 

     input1 = JOptionPane.showInputDialog ( "Type a whole number." );

     input2 = JOptionPane.showInputDialog ( "And another, please." );

     input3 = JOptionPane.showInputDialog ( "One more, if you would." );

 

     num1 = Integer.parseInt ( input1 );

     num2 = Integer.parseInt ( input2 );

     num3 = Integer.parseInt ( input3 );

 

     if ( num1 >= num2 )

        largest = num1;

     else

        largest = num2;

 

     if ( num3 >= largest )

        largest = num3;

 

     JOptionPane.showMessageDialog ( null ,
        "The largest is " + largest );

 

     System.exit ( 0 );

   }

}

Assuming that the numbers 8, 6, and 2 were typed in by the user in that order at the appropriate times, what would the final dialog box look like? Draw a specific and detailed rendition.