0% found this document useful (0 votes)
32 views9 pages

Sample Paper 01

The document is an examination paper for a Higher Diploma in Information Technology focusing on Object Oriented Programming in Java. It consists of five questions covering topics such as Java bytecode, class structures, exception handling, and design of classes and methods. The exam is closed book, lasts for three hours, and has a total of 100 marks available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

Sample Paper 01

The document is an examination paper for a Higher Diploma in Information Technology focusing on Object Oriented Programming in Java. It consists of five questions covering topics such as Java bytecode, class structures, exception handling, and design of classes and methods. The exam is closed book, lasts for three hours, and has a total of 100 marks available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Higher Diploma

in
Information Technology

Final Examination
Year 1, Semester 2 (2022)
January Intake

Object Oriented Programming (JAVA)


(IT1108)

Duration: 3 Hours

Instructions to Candidates:

 This is a closed book examination.


 This paper contains 5 questions on 8 pages without the cover page.
 Answer all questions on the WORKBOOK provided.
 Read all questions before answering.
 The total marks obtainable for this examination is 100.
Question 1 (20 marks)

a) Briefly explain how java bytecode can run on any platform. (4 mark)

b) What are the results of the following java statements? (2 marks)

Include your calculation as a proof.

i. int data= (3&8) | 5;

ii. int a= ((7-6%2*4+(5-3)) %2)+(4*2-6);

c) Rewrite the following code after Fixing the Syntax Errors. (4 marks)
class TestHome

public static void Main(String[] args)

float interest=4.7;

double answer=payRent();

System.out.println("rent is "+answer);

void payRent(float s)

return s*2;

d) “WeCare” is a gas distributing company located in Sri Lanka. A six digital (10 marks)
serial number is pasted on the gas cylinder to track the information about the
gas cylinder. The format of the serial number is as follows.

Serial Number: XX-dd#mm

Page 1 of 2
XX Value Meaning

RU Imported from Russia

ME Imported from Middle East

IND Imported from India

dd Value Meaning

Between 0 to 50 Low LP Gas Percentage

Between 51 to100 High LP Gas Percentage

mm-month imported.

Write a java program which takes the Serial number of the gas cylinder as a
string user input and print the decoded meaning to the screen based on the
details given in the table. You need to print the Serial number is valid or not.

Sample Input:

Enter Your Serial Number: RU-65#08

Sample Output:

Your Serial Number is Valid

Validated Details of the Cylinder.

Imported from Russia

65 % High LP Gas Percentage.

Imported in month 08

Page 2 of 8
Question 2 (20 marks)

a) Refer to the following code when filling the blanks (4 marks)


public ___ class GasCylinder

____ float Price=5900;

double LPRate=0.8;

public GasCylinder(float fprice,double LPRate)

Price=fprice;

_____.LPRate=LPRate;

______ double getDailyPrice();

 GasCylinder class should not be able to objects

 Price variable must remain same for all the objects/instances created.

 getDailyPrice method should not be have a method body.

b) What is the final output of the given code? (4 marks)


public class Exam{

static int p= -2;

static int q= -3;

public static void main(String[] args) {

new Exam().changeP();

new Exam().changeQ();

System.out.println(p);

System.out.println(q);

Page 3 of 8
}

void changeP() {

p*=2;

q/=3;

void changeQ() {

p*=2;

q*=2;

c) What is the purpose of Maven repository? how it can be used for your (2 marks)
group project?

d) Write a Java program which prints the following pattern to the screen using (10 marks)
loops.

2 4 6 8

10 12 14 16

18 22 24 26

Question 3 (20 marks)

a) Test scores of 4 students in SLIIT Academy for OOP subject is stored as (2 mark)
follows
Student ID Test Score

IT12345 92.5

IT12343 42.5

IT12342 52.5

IT12341 82.5

Explain what the advantages are of using an array for storing this information
by your own words.

b) Compare the differences between ragged array and rectangular arrays in java? (4 marks)

Page 4 of 8
c) Write a Java code segment to do the following tasks. (4 marks)

i. Create an ArrayList with specified data type Double with the initial
size of 10.

ii. Add 10 random numbers into the ArrayList

iii. Set the 5th element of the ArrayList into 23.4

iv. Clear the ArrayList

d) Treble Bicycle Selling company keep their prices of each bicycle in the (10 marks)
following table.

Bicycle ID Price Discount Applicable


B1001 3785 Y
B1002 4333 N
B1003 3666 N
B1004 5888 Y

Note: -10% discount will be awarded for each bicycle purchase is Discount
Applicable

1. Write a Java Programs which store the above details in a 2d array in


java
2. Calculate and print the Average Price of Products which has a
discount.

Question 4 (20 marks)

Page 5 of 8
a) Explain the purpose of handling exceptions using an example. (2 marks)

b) Re write the following code segment after handling all the exceptions that
might occur during the execution.
public static void main(String[] args) (6 marks)
{

String x=null;

int m =x.length();

int Y[]={12,25};

System.out.println(y[2]);

c) Explain best practices which can be applied when writing unit tests using (2 marks)
junit Framework.
d) Conduct the Junit testing for the following findmarks method. (10 marks)

public class Subject


{
int[] marksArray={23,45,56};

public String findmarks(int marks)


{
for(int i:marksArray)
{
if(i==marks)
return "Found";
}
return null;
}
}

Question 5 (20 marks)

Page 6 of 8
a) Create an abstract class called Clock using the details given below. (10 marks)

 Model-String
Private Instance Fields
 Type-String

public Instance Field Price double

Class Name: Movement

Public Instance Fields(S):

 NumberofGears integer
public Nested Inner Class
 WaterResistLevel float

Constructor: Write a constructor to


assign values (Taken as parameters) to
its instance variables.

Write a constructor to assign values (Taken


Outer class Constructor
as parameters) to its instance variables.

 abstract String getWatchDetails()

 String printDetails()
Public Methods
Returns the Model and Type
Concatenated in upper case

b) Create a Subclass called WristWatch which extends the Clock class as (5 marks)
given below.

Public instance
 BeltType String
fields

Write a constructor to assign values (Taken as parameters) to


Constructor
its instance variables.

 abstract String getWatchDetails()-returns details


Override
from printDetails() method in the superclass
public method
concatenated with the printDetails

c) i. Create a class called WatchShop which contains the main method to (5 marks)
achieve the following tasks.

Page 7 of 8
ii. Create an instance from WristWatch with following
values as constructor parameters.

Variable Value

Model Submariner

Type Automatic

NumberofGears 21

WaterResistLevel 50

BeltType Metal

iii. Create the following Specification description using


the above classes and methods.

Specification for Rolex Submariner

Watch Type: Automatic

Movement Specification

Number of Gears: 21

Water Resist Level :50 m

Belt Type: Metal

End of the Question Paper

Page 8 of 8

You might also like