2001ACTestQuestions

2001ACTestQuestions - Question/Answer Sheet - Page 1 -...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Question/Answer Sheet - Page 1 - CompSci 101 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (5 marks) What is the output of the following Java application? public class Q1 { public static void main(String[] args) { int i; double d; i = 6 % 10; System.out.println(i); i = 10 / 6; System.out.println(i); d = (int)(2.5 * 2.0); System.out.println(d); d = ((int)2.5 * (int)2.0); System.out.println(d); System.out.println(d + i); } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 2 - CompSci 101 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (5 marks) The applet below contains two TextField s and a Button . When the user presses the Button labelled " Swap ", any text that has been typed into the TextField s is swapped from one TextField to the other. For example, in the screen shots below, the user has typed the words " Summer " and " School " into the TextField s. As soon as the " Swap " button is pressed, the contents of the left TextField is swapped with the contents of the right TextField . The screen shot below illustrates this: For this question, you need to complete the actionPerformed() method, which should swap the contents of the two TextField s. import java.awt.*; import java.applet.*; import java.awt.event.*; public class Q2 extends Applet implements ActionListener { TextField tOne, tTwo; Button bSwap; public void init() { tOne = new TextField(10); tTwo = new TextField(10); bSwap = new Button("Swap"); bSwap.addActionListener(this); add(tOne); add(tTwo); add(bSwap); }
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED public void actionPerformed(ActionEvent e) { } } Question 3 (10 marks) Complete the paint() method for the applet which produces the drawing below. All of the parameters to the drawing methods should be based on the constant SIZE , so that the picture can conveniently be scaled. In the screen shot below, the value of SIZE is 50. The applet window is 200 pixels wide and 200 pixels high:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED If the value of SIZE is changed to 25, the drawing should appear as below, where again the applet window is 200 pixels wide and 200 pixels high: import java.awt.*; import java.applet.*; public class Q3 extends Applet { public void paint(Graphics g) { final int SIZE = 50; } }
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 16

2001ACTestQuestions - Question/Answer Sheet - Page 1 -...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online