0% found this document useful (0 votes)
4 views

CAT I Model Answers

PAPER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CAT I Model Answers

PAPER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

THE OPEN UNIVERSITY OF SRI LANKA

Faculty of Engineering Technology


Department of Electrical and Computer Engineering

Bachelor of Software Engineering

Continuous Assessment Test I (2019/2020)


EEI3262 – Introduction to Object Oriented Programming

Date: 06​th​ November 2019​ ​Time: 15:45 - 17:00

Instructions:
● Answer all the questions.
● Use comments on your code where applicable.
● You are recommended to use ​java programming language for all coding
problems. If you choose a different OO language, mention the used language
with every problem.
● This paper contains nine (9) pages.
● Time allocation is 75 minutes.
● This is a closed book examination.
● Number and attach any extra sheets and draft sheets used

Question 1 - Language fundamentals 30 marks


1.1 List all ​numeric data​ ​types ​in Java programming language. 6 marks
Correct answers :​ int, float, double, short, long, byte 1 mark/each
(case (ie, Capital/ Simple is not considered))

Wrong answers : Integer, String, char, array, unsigned, bit, bool, boolean
1.2 Briefly explain the role of a ​compiler​ and describe how Java Compiler(s) are different
from other compilers. 5 marks
Compiler is a computer program that ​converts/translates​ code written in a high level
programming language to a​ machine understandable form​. 3 marks
While other compilers convert the code into machine language java compilers convert
it to an​ intermediate form​ known as the ​byte code. 2 marks
1.3 ​Identify and circle the​ errors​ in the programs given below. A program may contain more
than one error. Write the identified errors with an explanation on the right side of the
paper.
If only 1 error is identified 1 mark
If some are identified 1 mark
If all are identified 1 mark
If non-errors are identified as errors -1 mark
9 marks
class Driver{ |
public static void main(String[] args)[ | ​F​or should be ​f​or
For{int i = 0; i =< 10; i++}( |
system.out.println(“i”) | ​s​ystem.out.println should be
) | S​ystem.out
] |
} | ​semicolon ( ​;​ ) - missing in line
4
|
|

class Phone{ |
string brand; | ​s​tring should be ​S​tring
string model; |​ ​s​tring should be ​S​tring
long IMEI; |
String os; |
| ​b​oid should be ​v​oid
boid public(Boolean stateOn){ | ​boid public should be
public void
if(stateOn) powerOn; | powerOn​();
else powerOff(); |
else restart(); | ​else without if
} |
} |
These 2 are not errors but marks won’t be reduced if identified : Use of {}, Boolean ->
boolean
class Stars{ |
| ​P​ublic should be ​p​ublic
Public static void main(){ | main(​String[] args​){
for(k--; int k = 50; k > 0){ |​ int k = 50; k > 0​; k--;
System.out.println(“ * ”); | is the correct order
if(k % 7 = 0){ | ​if(k % 7 ​==​ 0) // == operator
System.out.println(“”); | this line is correct
} |
} |
} |
} |
|

1.4 Complete the program given below so that it prints out the following pattern to the default
console using suitable data structures and a maximum of two System.out.print() /
System.out.println() statements. It is recommended to use only just one. 10 marks
1
1 3
1 3 6
1 3 6 10
1 3 6 10 15
1 3 6 10 15 21

class Pattern{
public static void main(String[] args){
//proper java syntax 2 marks
// using loops (while, do while, for) 2 marks
//using nesting. Loop inside Loop 2 marks
//OR if inside loop
//using an assignment like x += y 2 marks
// if i++ is used.(although not appropriate) 1 mark

//System.out.println(“”); OR System.out.print(“\n”); 2 marks


}
}
Question 2 - Control Structures in Java 30 marks
2.1 Name and define the 3 types of control structures and their variations. 10 marks
Sequence 2 marks
Selection 3 marks

Single Selection/ if
Double Selection/ if else 1 mark
Multiple Selection/ switch, if else if ladder

Iteration 3 marks
while
do while 1 mark
for
Missing marks are compensated for if explained using flowcharts.

2.2. ​Explain the behaviour of a ​do while loop​ with an example. 10 marks
The code in the do while loop is ​executed once before ​checking the condition and then
keeps running ​until the condition becomes false.
int x = 5; explanation : 5 marks

do{ correct example : 5 marks


System.out.println();
x++;
}while(x < 10);

2. 3. Write a program that will calculate the interest given the account type and the account
balance. The interest calculation will happen as follows, 10 marks

below 10,000 10,000 - 50,000 50,000 - above 100,000


100,000

Type ‘r’ +2% +2.5% +3% +5%

Type ‘s’ +4% +5% +6% +8%


//Proper syntax and readable code 4 marks

if(type == ‘r’){ switch(t){


case ‘t’:
}else if(type == ‘s’){ OR break; 2 marks
case ‘s’:
} }

if(balance < 10000){

}else if(balance < 50000){ 2 marks

}else{

interest = balance * 1.1; etc


OR 2 marks
interest *= 1.1; etc
Interest = balance + balance * 10 / 100;

Question 3 - OOP preliminaries; Classes, Objects and methods 40 marks


3.1 Differentiate between a class and an Object 10 marks

A class is a​ common group​ of things which in OOP context is a​ template​ which is an


abstract ​representation of an entity in the real world. Classes are used for creating objects

Objects are individual ​instances/occurrences​ of an object or a thing. They possess


properties. They are created using classes.
3.2 ​Draw a class diagram (with one class) representing a Book, including suitable attributes
and behaviours. 10 marks
3.3 Write a Class in Java to represent the above and another “Driver class” (a class
containing the main method) to demonstrate its usage by setting values to the defined
attributes and invoking the behaviours. 10
marks

Book b = new Book(); ​ 5 marks

//attributes initialized AND/OR behaviours invoked 5 marks


sherlockHolmes.setAuthor(“Arthur Conan Doyle”);
OR
Book hp = new Book(“Harry Potter and the Philosopher's Stone”,
“JK Rowling”, 1997);

3.4 Identify the parts of a java method marked by arrows 10 marks


1 : Access Modifier/ Access Specifier 1 mark
2 : Return type 1 mark
3 : name / identifier 1 mark
4 : parameter / parameter list argument is wrong 1 mark
5 : return/ return statement 1 mark
6 : method call/ invocation 1 mark
7 : argument parameter is wrong 1 mark
Total for 3.4 = sum of the above / 7 X 10 (to adjust for 10 marks)
– END –
Copyrights Reserved

You might also like