ge
THE UNIVERSITY OF DODOMA
COLLEGE OF INFORMATICS AND VIRTUAL EDUCATION
SCHOOL OF INFORMATICS
a
ity
yer Oy
°
vwod
%e
eS
"seing Koo
UNDERGRADUATE SUPPLIMENTARY/SPECIAL
EXAMINATION
. J 2017/2018
CS 213: OBJECT ORIENTED PROGRAMMING IN. Jae
Date: 24'" September, 2018
Time Allocated: 3 Hours
Instructions:
1. This examination consists of six (¢
2. Answer all questions from”SECTION A (60
estion ON, Yor
a program in Table 1
a) What of the
Table 1: Java p
public class Exceptions{
2, public static void main(String[]
| 3. String b[] = new String[3];
4. tryf
| 5. System.out.printIn(b[1]);
16. intx = 5/0;
lie j}catch(ArrayIndexOutOfBoi
System.err printin(“errorA");
9. }eatch(ArithmeticExceptioi
| 10. System.err printin("errorB"),
ee
| 12.)
| 13}
a) The program in Table 2 has |
error, trTable 2: Java program
abstract class Student
public abstract double getPassMark();
}
class DiplomaStudent extends Student{
Private final double passMark;
private final double diplomaPassMark:
public DiplomaStudent(double PpassMark, double
diplomaPassMark){
8. this. passMark = passMark:;
9._ this.diplomaPassMark = diplomaPassMark:
10.3
11. public double getDiplomaPassMark(){
12. return diplomaPass Mark;
13),
14. public double getPassMark(){
15. return passMark;
16. }
7g
18. public class EmployeeTest {
19. public static void main(String args[]){
20. Student employees = new DiplomaStudent(50.0, 60.0);
21. System. out.print{("pass mark: %,.2f%n", employees
.getPassMark());
22. System.out.printf{("pass mark: %,.2f%n",
employees. getDiplomaPassMark());
230i)
24.}
NAOAWHR
Page 3 of 8jon TWO 4
Question shod header for each of the following
ea me
writ :
4 Method basket, which contain a String
i
cup, and does not return any value,
Method dodoma, which takes a doul
floating-point arguments radius and r¢
precision, floating-point result.
iii
it returns an integer.
iv. Method instructions, which does not
and does not return a value.
y. Method intToFloat, which takes
number and returns a float.
b) What will be the output of the progr
Table 3: Java p
| public class Stri &
public static void main(String an
System. out. println("Was it acaon Three
write a simple java
constructors overloading. The
called Student, instance
registrationNumber, Age and hte
should be responsible to initialize o
reate a drive class (a class
demonstrate the work of Studer
What will the output of the p
. class Aff
class B extends Af}
class C extends Bf}
class D extends C{}
5. public class Test{
;, public static void mai
. Aa=new AQ);
Bb =new BO;
Ce=new CO;S$)
sECTION B40 MARK: )
Four
Question cut component
Write a java program using swing
which contains two text I fields label
name and age respectively, four
Exit, When user enters nam
submit button, the name and age 5}
abase, in the
ould be submitted to MyS4
table called uset_! table. W!
etrieved from
ser clicks ch
database named user_dat
user clicks view button, the name and age should be r
database and displayed on the dialog window. When vs
+t field has to be cleared should it contain any data val
button, the text
When user clicks exit button a program should close. In case
database connection failure, a program should handle the thro’
Exception using try-catch block with the message “database connecti
failed” displayed on the dialog window. All used resources shot
finally be closed inside try-finally block. (20 Marl
Question Five
Implement the Shape hierarchy shown in Figure 1. Each Th
DimensionalShape should contain method esata he
of the two-dimensional shape. Each ThreeDi
have methods getArea and Sela 2
volume, » Tespectively, of the e-dithat uses an array of Shape references to objects of each Concrete class
in the hierarchy. The program should print a text description of the
object to which each array element refers, Also, in the loop that
processes all the shapes in the array, determine whether each shape is a
TwoDimensionalShape or a ThreeDimensionalShape. If it’s a
TwoDimensionalShape, display its area. If it’s a
ThreeDimensionalShape, display its area and volume. (20 Marks}
Figure 1: Inheritance hierarchy
Shape
ThreeDimentionalShapearks are
Your program shall check that the m:
between 0 and 100.
Consider the classes Student and Address. Every student has
address, therefore the relationship between student and oa
is a Has-A relationship. But if you consider it in the reverse, J
would not make any sense as it is not necessary for the Addre.
fo contain a Student. Write three java Classes to implement t
relationship. Note that Address may contain street number, ci
and country while student class may have address, student na
and student id, [10 Marl