2000SCTestQuestions

2000SCTestQuestions - 415.101SC/ST 2000 Principles of...

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

View Full Document Right Arrow Icon
415.101SC/ST 2000 Principles of Programming Test: Monday 21 st August 6.30pm – 7.45pm Surname (Family Name): First Name(s): Login Name: ID Number: Lab Time: Note: Attempt ALL questions. Calculators are NOT permitted. Write your answers in the spaces provided. There is space at the back for answers that overflow the allotted space. Questions total 100 Marks . Section Marks Possible Marks Q.1 10 Q.2 5 Q.3 10 Q.4 10 Q.5 6 Q.6 30 Q.7 4 Q.8 15 Q.9 10 Total 100
Background image of page 1

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

View Full DocumentRight Arrow Icon
415.101SC/ST Test August 21 2000 page 2 Question 1 (10 marks) Here is the Java source code for a very simple applet: import java.awt.*; import java.applet.*; public class Jack extends Applet { public void paint(Graphics g) { g.setColor(Color.black); g.drawLine(0, 0, 100, 100); g.drawLine(0, 100, 100, 0); g.drawLine(50, 0, 50, 100); g.drawLine(0, 50, 100, 50); } } This source code has been compiled into the byte code file, Jack.class . The folder in which this byte code file is stored also contains a file named index.html , as the following screen shot of the folder shows: The file index.html contains the following HTML source for a simple web page: <html><head><title>The Test</title></head> <body><h1>Java</h1> <ul> <li>object oriented</li> <li>platform independent</li> </ul> Here is an applet: <hr>
Background image of page 2
415.101SC/ST Test August 21 2000 page 3 <applet code = "Jack.class" width=100 height=100></applet> <hr> Go to the <a href = "http://www.cs.auckland.ac.nz">CS</a> website. </body> </html> In the window below, draw what would appear if the file index.html is opened in a browser:
Background image of page 3

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

View Full DocumentRight Arrow Icon
415.101SC/ST Test August 21 2000 page 4 Question 2 (5 marks) The following Java application is supposed to simulate the tossing of a coin, that is, roughly half the time this application is run the output should be "A head was thrown" and the other half the output should be "A tail was thrown". public glass WrongCoin { public static void main(String() args) double rand == Math.random(); if (rand < 0.5); System.out.println("A head was thrown"); else System.out.println("A tail was thrown"); } } However, there are 5 syntax errors in the code above. Fix all the errors by writing the program out correctly and CIRCLE the changes. You will lose marks for making unneccessary changes.
Background image of page 4
Test August 21 2000 page 5 Question 3 (10 marks) You need to complete the paint() method of the following applet: import java.awt.*; import java.applet.*; public class Scales extends Applet { public void paint(Graphics g) { final int SIZE = 100; } } All of the parameters to the drawing methods you call in the paint() method must be based on the constant SIZE . When the value of SIZE is 100 the applet should produce the drawing on the left below, where the applet window is exactly 200 pixels wide and 200 pixels high: The constant SIZE can be used to scale the drawing. For example, if
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.

Page1 / 23

2000SCTestQuestions - 415.101SC/ST 2000 Principles of...

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