You are on page 1of 6

SUPPLEMENTARY EXAMINATION

PROGRAMME Bachelor of Commerce in Information and Technology Management

MODULE Informatics 1A

YEAR One (1)

INTAKE July 2017

DATE 09 January 2018

TIME 09h00 – 12h00

DURATION 3 hours

TOTAL MARKS 100

INSTRUCTIONS TO THE CANDIDATE

1. Questions must be attempted in the answer book provided.


2. All queries should be directed to the invigilator; do not communicate or attempt to communicate with any
other candidate.
3. You have THREE HOURS to complete this paper. You are not allowed to leave the examination room within
the first hour and in the last 15 minutes of this examination.
4. This is a CLOSED BOOK examination.
5. Read ALL instructions carefully.

02
Answer ALL questions.

QUESTION 1 [20 MARKS]


Choose the correct option. Write down the question number and the correct answer next to it. E.g. 2.21 A

1.1 Which of the following is not an IDE:

A) Eclipse
B) Excel
C) JGrasp
D) NetBeans

1.2 Which of the following operators is known as a “logical connective”:

A) !
B) &&
C) ++
D) !=

1.3 Sub-programs within a program are called:

A) classes
B) objects
C) methods
D) code blocks

1.4 What is the full form of JDK?

A) Java Data Kit


B) Java Defination Kit
C) Java Development Kit
D) Java Design Kit

1.5 The statement: i++; is equivalent to_________.

A) i = i + i;
B) i = i + 1;
C) i = i - 1;
D) i - - ;

1.6 What value is stored in num at the end of this looping?


for (num = 1; num <= 5; num++)

A) 1
B) 4
C) 5
D) 6

02 1
1.7 Java is defined as a(n) ______________.

A) assembly language
B) machine language
C) low-level language
D) high-level language

1.8 The expression t == b is called a(n) ____________.

A) Comparison statement
B) Assignment statement
C) Repetition statement
D) Selection statement

1.9 Use ________ to obtain the int equivalent of the String.

A) integer Variable
B) main (String)
C) public class (String)
D) parseInt ()

1.10 Java has many of the features of:

A) Pascal
B) C++
C) Cobol
D) Scratch

1.11 The first step in problem solving is to:

A] code the problem


B] save the problem
C] understand the problem
D] write the algorithm

1.12 Which one of the following is an incorrect variable name?

A) Surname
B) $total
C) _abc_
D) 1surname

1.13 Boolean expressions are put together using:

A) Repetition loops
B) Relational operators
C) Counter variables
D) Methods

02 2
1.14 _______ defines a list of items which are operated on by the algorithm.

A) Data
B) Process
C) Output
D) Variables

1.15 _______ are often used to document a program and improve its readability.

A) Objects
B) Classes
C) Methods
D) Comments

1.16 You can also show output in the command line window, using the methods:

A) JOptionPane.showInputDialog();
B) JOptionPane.showMessageDialog();
C) System.exit(0);
D) System.out.println();

1.17 A(n) __________ occurs when a program has a grammatical mistake like missing punctuation.

A) syntax error
B) run-time error
C) logic error
D) hidden error

1.18 Invoking a method means:

A) checking the method for errors


B) designing the method
C) asking the method to do its job
D) revising the method

1.19 What output does the code below represent?


JOptionPane.showMessageDialog(null, “Hello world!”)

A) null
B) Message
C) Hello world!
D) Hello

1.20 The _____ operator does addition when applied to two numbers, and strings concatenation when
applied to two Strings , or a String and a numeric value :

A) –
B) +
C) *
D) \

02 3
QUESTION 2 (20 Marks)
Determine if the following statements are True or False. Write down the question number and the correct answer next to
it. E.g. 2.21 True

2.1 It is important to test and evaluate a computer program.


2.2 Java is a high-level language.
2.3 Methods are one of the major structuring mechanisms for Java programs.
2.4 The Java compiler translates Java programs into machine language programs.
2.5 Pseudocode is a mixture of English and a programming language.
2.6 The computer will not print an error message when a logic error occurs.
2.7 System.out is an example of a method.
2.8 An upper-case letter is considered to be the same character as a lower-case letter in Java.
2.9 The boolean type has only two values.
2.10 Every statement with if must also include else.
2.11 The == operator can be used to see if two strings have the same characters.
2.12 The body of any while loop will be executed at least once.
2.13 JOptionPane is a class which allows us to display a message dialog box.
2.14 Comments are printed on the screen when the program is executed.
2.15 Some programs never halt.
2.16 A method cannot make changes to its formal parameters.
2.17 Variables should always be declared as locally as possible.
2.18 A computer is a general-purpose device that behaves according to the sets of instructions and data it
is provided with.
2.19 When it is not known in advance how many times a set of statements will be repeated, a counter value can be used to
terminate the repetition.
2.20 The Java API is a useful collection of classes that you may use in your programs.

QUESTION 3 (20 Marks)

Variables provide a convenient way to store information in the computer’s memory temporarily. When information is stored in a
variable, it can use that information whenever it is needed in the program by calling the name given to it. The value may be
changed at any stage. With this in mind, answer the questions that follow:

3.1 List and explain the THREE (3) parts of a variable. (6 marks)

3.2 Provide examples of declaring a variable to the following scenarios: (4 marks)

3.2.1 Declaring an integer variable


3.2.2 Declaring a string variable
3.2.3 Declaring a float variable
3.2.4 Declaring a single character variable

3.3 Briefly discuss the rules for naming variables (3 marks)

3.4 Write a Java program to store three numbers into variables num1, num2 and num3 and then display those numbers in a
dialog box. (7 marks)

02 4
QUESTION 4 (20 Marks)

4.1 Define the following concepts:

4.1.1 Assembler language (2 marks)


4.1.2 Class (2 marks)
4.1.3 Variables (2 marks)
4.1.4 Dry running (2 marks)
4.1.5 Semantic error (2 marks)

4.2 The following program below contains 10 errors. Write down the line numbers together with the corrected program
statement: (10 marks)

1 public class Tricky {


2 public static main (String args) {
3 System.out.println(Hello world);
4 system.out.Println(“Do you like this program”?);
5 System.out.println()
6
7 System.println(“I wrote it myself.”;
8 {
9 }
Line 2: missing void before main
Line 2: missing [] after String
Line 3: missing “ “ marks around Hello World
Line 4: system should be System (uppercase S)
Line 4: Println should be println (lowercase p and fixed spelling)
Line 4: ? should be before “
Line 5: missing semicolon after ()
Line 7: missing ) after “
Line 8: System.println should be System.out.println
Line 8: { should be }

QUESTION 5 (20 Marks)

5.1 Briefly explain TWO (2) types of methods. (5 marks)

5.2 State whether the following are valid or invalid method names: (5 marks)

5.2.1 $myMethod()
5.2.2 ____addingNumbers()
5.2.3 2012AverageCalculator()
5.2.4 guess The Answer()
5.2.5 First_Name()

5.3 Write a complete Java program called Display that has a void method called ShowMessage() that accepts a string
parameter msg. The method call in the main program should produce the following output: (10 marks)

It’s a nice day!

END OF PAPER

02 5

You might also like