Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
228 views8 pages

HNDIT1209 Object Oriented Programming I Programming in JAVA

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

'[All Rights Reserved]

I~ I !/~~!~/TUTE OFADVANCEDTECHNOLOGICALEDUCATION
(Established in the Ministry of Higher Education, vide in Ad No. 29 of 1995)

Higher National Diploma in Information Technology


First Year, Second Semester Examination - 2015
HNDlT1209/1T 2001- Object Oriented Programming I Programming in JAVA

Instructions for Candidates: No.ofquestions:06

ee
Answer five (05) questions only No. of pages : 07
All questions carry equal marks. Time : Three (03) hours

Question 01

al
(i) Write the default value of given data types in JAVA.

a. byte

m
b. int

c. String
co
d. boolean

(04 marks)
rin

(ii) Write the output of the following code segments.

a.
int x = 2;
IT

System.out.print(x +" != ");


System.out.println(2*x);

b.

System.out.print("\"Hello\\\n Ann!");
AT

c.

int break = 3;
System.out.print( --break);
(06 marks)
(iii) Evaluate the following expressions for x=Z, y=5 and z=9

a. x + y * 5-z
b. (zJx )+ y/2 + xi2

c. z%5 + 5*3+1

(06 marks)

(iv) What is data type conversion? Explain with an example.

(04 marks)

(Total 20 marks)

ee
Question 02

al
(i) Rewrite the given code segment with only one if statement.
if(attendance >= 80)
if(assignmmentMarks >= 40)

m
eligibility = true;

(04 marks)

(ii) Consider given code segment.


co
int number = 2;

Design a SWITCH to display bellow resuJt.


rin

Value of number variable Display message


1 Number is One
1 Number is Two
IT

Any other value Number is not defined

(06 marks)

(iii) Write general syntax of Do - While loop. (04 marks)


AT

(iv) Write a complete JAVA program to display Summation of Even numbers between 0 and
100 using a/or loop. (0 and 100 are not included)

( 06 marks)

(TotallO marks)

2
HNDIT - HNDITl2091lT 2001 - Object Oriented Programming I Programming in JAVA 2015
r :,J'

Question 03

(i) What is an Array? (02 marks)

(ii) Write the code segments to perform following tasks.

a. Create a String array named days which can hold 7 String values.

(02 marks)

b. Create a char array named vowels and initialize it. (Either capital letters or simple
letters)

(02 marks)

ee
c. Print the second element in the following integer array. Array name is score.

al
(02 marks)

d. Replace the value 7 with the value 9 in the following integer array. Array name is
score.

m
co
(02 marks)

(iii) Write answers to question a to c by considering the given JAVA code segment.

String x="I love Java Programming";


rin

a. What is the output of the following code?

System.out.printlmx.cbareusj);
IT

(02 marks)

h. Write the line of code to get the number of characters in the above string.

(02 marks)
AT

c. What would be the output of following code segment?

System.out.println( x.subString( 1,4»;

(02 marks)

3
HND1T - HNDITI 209 lIT 2001 • Object Oriented Programming I Programming in JAVA 2015
(iv) Consider the given code segment.

String x="llove Java Programming";


String y ="1 love Java";

Write the code segment to compare two variables (x and y). If x and y variables have same
value display a message "same" otherwise display a message "different".

(04 marks)

ee
(Total 20 marks)

al
Question 04

(i) Consider the following scenario.

m
You are asked to design a cylinder class using JA VA language to keep records on
cylinders manufactured by a company. The company needs to store the cylinder color,
radius and height for each cylinder. Design the cylinder class with following
properties.
co
a. Encapsulated instance variables: color, radius and beight.

(03 marks)
rin

b. Constructor of the class to initialize encapsulated variables with passing


arguments from calling program.

(04 marks)
IT

c. PublicgetColor method to return the color of the cylinder.

(03 marks)

d. Public displayVolume method to calculate the volume of the cylinder and print it.
AT

(Volume of a Cylinder = (2217) .•• radius! .•. height) (02 marks)

e. Write the code segment to create an instance of the cylinder class passing following
values for the instance variables.

color = red, radius = 7.0, height = 20.0

(02 marks)

4
HNDIT - HNDITl209 / IT 2001 - Object Oriented Programming / Programming in JA VA 2015
(ii) What is an Exception in JAVA?

(02 marks)

(iii) Write a Java code using try catch blocks to handle the exception when trying to access
an array index out of its range.

(4 marks)

(Total 20 marks)

ee
Question 05

(i) Consider given code segment. (Read the comment carefully)

abstract class Shape


{

al
II Shape contains abstract methods only
}

m
a. Can you create an object using Shape class?

(02 marks)
b. Explain your answer.
co
(02 marks)

(ii) Write a JA VA code segment to design a class named as CheckingAccolint using the
rin
bellow interface. (You are not expected to define body of the Checking.Account class)

public interface BankAccount


{
II Code here
}
IT

(04 marks)
(iii) Write answers to a and b from the given code segment.

public class Ati extends Sliate


{
AT

II Code here
}

a. What is the name of Supper Class? (02 marks)

5
HNDIT - HNDITl209 / IT 2001 - Object Oriented Programming / Programming in JAVA 2015
b. What is the name of Sub Class?

(02 marks)

(iv) When methods are overloaded, explain how JA VA would select matching method.

(02 marks)

(v) What are the ~tages ofTbread Life Cycle in JAVA?

(04 marks)

(vi) Name a class or an interface which can be used to create a thread in JAVA.

ee
(02 marks)

(Total 20 marks)

al
Question 06

m
(i) You are given App.class applet file. You would be asked to display that in your web
browser 300 pixels width and 250 pixels height screen. Write the suitable HTML tag(s) with
attribute values to display your applet. (You are not expected to write complete HTML file)
co
(04 marks)

(ii) Write a JAVA code segment to draw a Line between (l0, 10) and (50, 50) coordinates.
(Hint: Use bellow incomplete JA VA code segment)
rin

import java.awt. "';


import javax.swing. "';

public class App2 extends JApplet {


IT

public void paint(Graphics g) {


1/ Code here
}

(06 marks)
AT

6
HNDIT - HNDIT! 2091 IT 2001 - Object Oriented Programming 1 Programming in JAVA 2015
· I

(iii) Write complete JAVA codes to display given user interface.

ee
(10 marks)

al
(Total 20 marks)

m
co -END-
rin
IT
AT

7
HNDIT - HNDITI 209/ IT 2001 - Object Oriented Programming / Programming in JAVA 2015
AT
IT
rin
co
m
al
ee

You might also like