2001FCTestAnswers

2001FCTestAnswers - C ompSci 101 FC 2001 Terms Test Answers...

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

View Full Document Right Arrow Icon
CompSci 101 FC 2001 Terms Test Answers Question 1 (10 marks) Part A (5 marks) The contents of a simple HTML file is given below. The page contains an applet called Test , which has been compiled, and the class file for this applet is in the same directory as this HTML file. The HTML contains 5 errors. Locate each of the 5 errors in the HTML below, and write the correction underneath the line with the error. You will lose marks for making unnecessary changes. <hmlt> <html> <head> <title>Terms Test</title> <head> </head> <body> <h1>Here is an applet:</h1> <applet class ="Test.class" width=100 height=100> </applet> code What do you think? <hr> The answers to the test can be found <a = "http://www.cs.auckland.ac.nz/ans.html">here</a>. href </body> </html> (5 marks)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Part B (5 marks) There are 5 syntax errors in the following code. Locate each of the errors in the code below, and write the correction in the space provided underneath the line with the error. You will lose marks for making unnecessary changes. import java.awt.*; import java.applet.*; /** Check for syntax errors @author Department of Computer Science @version 30 April 2001 // */ public class CoinToss extends applet { Applet public void init () { int rand == (int)(Math.random * 3); = random () if (rand == 1) System.out.println("Heads"); else if (rand == 2) System.out.println("Tails"); else System.out.println("On its side!") ; } } (5 marks)
Background image of page 2
Question 2 (15 marks) Part A (5 marks) Complete the code segment below so that it prints out a random number between 10 and 20 inclusive. That is, the smallest possible random number will be 10, and the largest possible random number will be 20. public void init() { int randomNumber; randomNumber = (int)(Math.random() * 11) + 10; System.out.println(randomNumber); } (5 marks) Part B (10 marks) What is the output of the following code segment: int i; double d; i = 5; d = 5; System.out.println(i - d); System.out.println(i + (d + "")); System.out.println((i + d) + ""); System.out.println((int)(i * d) / (i + d) - i); System.out.println((int)d + i); (10 marks)
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 3 (5 marks) What is the output from the following program? import java.awt.*; import java.applet.*; public class Variables extends Applet { int aInt = 1; int bInt = 2; int cInt = 0; public void paint(Graphics g) { int aInt = 200; System.out.println(aInt + bInt); System.out.println(cInt); } public void init() { int aInt = 10; int bInt = 20; cInt++; System.out.println(aInt); System.out.println(bInt); System.out.println(cInt); } } (5 marks)
Background image of page 4
Question 4 (10 marks) Part A (5 marks) Evaluate the following boolean expressions to true or false . int i = 10; int j = 20; int k = 30; i) (!(i <= 10) || ((k - j) != i)) false ii) i + k < 35 || k < j + i || j < k true (5 marks) Part B (5 marks) Write a boolean expression for the following descriptions, where value is an integer variable.
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

2001FCTestAnswers - C ompSci 101 FC 2001 Terms Test Answers...

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