Anda di halaman 1dari 5

INTERNATIONAL DIPLOMA IN COMPUTING

INTRODUCTION TO JAVA (C1022) ASSIGNMENT TERM 1 2008 Instructions:


Answer ALL questions Marks will be awarded for good presentation and thoroughness in your approach

NO marks will be awarded for the entire assignment if any part of it is found to be copied directly from printed materials or from another student. Complete this cover sheet and attach it to your assignment.

Student declaration:
I declare that: I understand what is meant by plagiarism The implication of plagiarism has been explained to me by my institution

This assignment is all my own work and I have acknowledged any use of the published and unpublished works of other people.
Students signature:. Total number of pages including this cover page Submission Date StudentsID StudentsFull Name LecturersName OFFICIAL USE ONLY Due Date Class Code 22/02/08 Date:

Markers comments

Markers name

Marks Awarded

/100

SECTION A

DIC\C1022\T108\ASG\QP

Page 1

[40 marks] Answer ALL questions in this section. A1. Write Java statements to accomplish each of the following: a) Declare a variable reply to be of type char. [2]

b) To compare the contents of both variables pass and word of type String. [2] c) To assign a float value 2.5 to a variable number. [2] [2] e) Declare a method view that does not return a value and has no arguments. [2] A2. Draw the following symbols used in a program flowchart: a) Process b) Connector c) Input d) Decision e) Start A3. [1] [1] [1] [1] [1] d) Display a message happy new year using a method from the Systems class.

State which of the following statements are CORRECT or INCORRECT. [8] a) It is not an error not to end a Java file name with the .java extension. b) Omitting the semicolon at the end of a statement is a syntax error. c) The + operator can be used for string concatenation. d) Infinite loops are caused when the loop-continuation condition in an iteration structure never becomes false. e) The method toUpperCase() converts any string or character to its uppercase equivalent. f) A TextField must be created with initial text and with or without a specified size.

DIC\C1022\T108\ASG\QP

Page 2

g) A loop that never ends is called an infinite loop. h) To import an entire package of classes, an asterisk(*) can be used as a wildcard symbol to represent all the classes in a package. A4. Identify the layout manager, component or method which will perform the following: b) A built-in class that holds text that can be displayed within an applet. c) A component which is used to display a series of items from which the user may select one or more items. d) The user requires the name entered to be stored in lower case. e) A window component which allows the user to click to trigger a specific action. f) A layout manager which allows the programmer to arrange the window components into five areas: north, south, east, west and center. A5. State the value of each of the following Boolean expressions. a) 2 + 17 * 3 = = 21 b) 17 / 2 + 2.5 * 3 >= 18 c) 25 % 10 * 5 < 40 d) 27 % 9 != 4 e) 18 / 2 + 6 / 2 != 12 f) (3 + 8) % 5 >= 5 A6. Identifiers are names that are given to variables, classes or methods. List the THREE requirements which must be met when declaring identifiers. A7. [3] [6] [6] a) A window component into which a user can type a single line of text data.

Name any TWO types of access modifier that define the circumstances under which a class or class members in programs can be accessed. [2]

DIC\C1022\T108\ASG\QP

Page 3

SECTION B
[60 marks] Answer ALL questions in this section. B1. a) Identify and correct the errors in each of the following codes: i) The following should print whether integer value is odd or even: switch(value % 2) { case 0 : System.out.println(Even integer); case 1 : System.out.println(Odd integer); } ii) public static void float(int a); { int a; System.out.println(a); } b) Enter a number [6] [4]

number >0

Display total

accumulate total

Enter a number

DIC\C1022\T108\ASG\QP

Page 4

Write a Java segment to represent the above flowchart.

[14]

c) List and explain briefly any THREE benefits of object-oriented programming. [6] B2. a) Explain the difference between a counter-controlled repetition and a sentinelcontrolled repetition. [4]

b)i) Write a method header hypotenuse that takes two values side1 and side2 of type double and returns a double result. [3]

ii) Declare an array called realnumbers, which is a one dimensional array to store numbers of type float. Assuming that the size of the array is 10. c) Explain the meaning of the following Java statements. i) Button calbutton = new Button(calculate); ii) g.drawLine(30, 50, 100, 50); iii) int[] marks = {56, 70, 80}; [3] [4] [4] [4]

d) Write a Java program using the drawRoundRect() method from the paint() method to draw a circle with the arguments as follows: x1 and y1 : both 30 width and height : both 100 Assuming Graphics object g as the argument to the paint() method. [8]

DIC\C1022\T108\ASG\QP

Page 5

Anda mungkin juga menyukai