Public void e if egetsource b3 number number 3

This preview shows page 13 - 17 out of 24 pages.

public void actionPerformed(ActionEvent e) { if (e.getSource() == b3) number = number - 3; number = number - 1; System.out.println(number); } } For this question, you need to do two things: 1) draw approximately what the user interface will look like, ie. where the JButton s will be positioned 2) determine what the output of the program will be when the JButton s are pressed in a certain sequence.
Image of page 13

Subscribe to view the full document.

Question/Answer Sheet - Page 14 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Draw the approximate positions of the three JButton s in the window below. All the information you need to know is given below: The size of the JPanel (which is the drawable area and does not include the title bar of the window or the borders of the window) is 200 pixels wide and 200 pixels high Each JButton will be exactly 70 pixels wide and 20 pixels high The smallest possible gap between the edges of any two JButtons and between the edge of a JButton and the edges of the JPanel will be 10 pixels (5 marks) What will be the output of the program when the JButton s are pressed in the following sequence: 1) the JButton labelled "One" is pressed, 2) then the JButton labelled "Two" is pressed, 3) then the JButton labelled "Three" is pressed, 4) then the JButton labelled "Three" is pressed again, 5) then the JButton labelled "Two" is pressed, 6) then the JButton labelled "One" is pressed 9 5 1 0 (6 marks)
Image of page 14
Question/Answer Sheet - Page 15 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 9 (8 marks) There are four incorrect lines in the application program Q9 below. Find and correct the lines with errors so that the program Q9 executes and produces output as in the examples shown below – the output must be identical to that shown: Example 1: C:\> java Q9 When number1 is 1, number2 is 6.283185307179586, and number3 is 3.141592653589793. Example 2: C:\> java Q9 When number1 is 6, number2 is 37.69911184307752, and number3 is 113.09733552923255. Example 3: C:\> java Q9 When number1 is 9, number2 is 56.548667764616276, and number3 is 254.46900494077323. The source code for the application program Q9 is given below. For each error, you need to clearly circle the error and provide a correction so that the program will compile and execute correctly. You do not need to write out the whole line of source code again, as long as you indicate your corrections clearly. public class Q9 { public static void main(String[] args) { int number1; double number2; number1 = (int) (Math.random() * 10); number2 = Math.PI * number1 * 2; System.out. print ("When number1 is " + number1); System.out.print(", number2 is " + number2); System.out.println(", "); double number3 = Math.PI * Math.pow(number1, 2); System.out.println("and number3 is " + number3 + "."); } } (8 marks)
Image of page 15

Subscribe to view the full document.

Question/Answer Sheet - Page 16 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 10 (10 marks) Consider the program shown in the screenshots below. Each time the program is run, a small dot is drawn at a random location on the screen. Several squares are also drawn. Finally, a String is drawn to the screen which indicates how many of the squares are positioned so that the centre of the dot is inside the square.
Image of page 16
Image of page 17
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern