MIS-B310                                                                              Name __________________

2nd Quiz                                                                                                                    (50 pts.)

 

Correct that code (6 questions – each question worth 3 points).  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.             if    {   mark   <   100   }

      books   =   books  +   1   ;

 

2.             Joptionpane.showMessageDialog ( null , " Greetings " ) ;

 

3.             public class Orange extends Applet {

 

4.             String leaderText ;
      double leader ;


      leader = Integer.parseInt ( leaderText );

5.             if   (   paul   >=   18   ) {

      System.out.println  (  " You can vote so " )

      System.out.println  (  " go to the polls now  " )
      }

 

      else 

            System.out.println  (  " You can't vote." )

 

6.             int 2ndnumber ;

 

 

Create that code (2 questions – each worth 4 points)

 

7.       Type of program: application.  Write a line of code that will create an input dialog box that asks for a decimal number and assign it to a variable called myCall.  (Choose your own phrasing of the request.)






 

 

 

8.       Type of program: application.  Create a line of code that will add 1 to a variable called x ONLY IF x is less than 5. Assume that x has already been declared and initialized.






 

 

 

 


What's my output? (2 questions – each worth 10 points)  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.