You are on page 1of 2

Page 1 of 2 PAPER REF.

NO

BABCOCK UNIVERSITY
DEPARTMENT OF SOFTWARE ENGINEERING

[QUESTION PAPER] TITLE: PROGRAMMING IN JAVA (COSC205)


FINAL TAKE HOME (ISSUED: 04/12/2022.4.25am; DUE DATE: 09/12/2022; 10am)

1) Mention at least 3 important characteristics of a constructor method.


2) What is the scope of a constructor method?
3) Distinguish between a local variable, an instance variable and a static variable?
4) The set method could also be used to validate data before assigning it to the data member. Write a
set method that validates user’s input for a clock object such that “26:50:12” would be alarmed
invalid for hh:mm:ss format (hours can’t be up to 26).
5) Write a program using a loop statement to sum the elements of the following array and print out the
result: float temperature[]= {1.0, 3.4, 2.5, 9.0, 7.5, 5.0, 4.0 };
6) Write a Java code to make 3 password guesses to gain access into a system using JOptionPane static
functions for input and output.
7) A magic word square is a square where a word can be formed from reading each row and each
column. For example, the following is a 4 by 4 magic word square:

‘P’ ‘R’ ‘E’ ‘Y’


‘L’ ‘A’ ‘V’ ‘A’
‘O’ ‘V’ ‘E’ ‘R’
‘T’ ‘E’ ‘N’ ‘D’

a) Declare and initialize a 2D array, magicSquare, to hold the words illustrated above
b) Write a method, displayRow, that accepts the magicSquare array and a row number and displays
the word in that row.
c) Write a method, displayColumn, that accepts the magicSquare array and column number and
displays the word in that column
d) In a two dimensional array named truthTable, what is the difference between these two
references: truthTable.length and truthTable[0].length

8) Create a class called Employee that includes three pieces of information as data members—a first
name (type string), a last name (type string) and a monthly salary (type int). Your class should have
a constructor that initializes the three data members. Provide a set and a get methods for each data
member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class
Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then
give each Employee a 10 % raise and display each Employee’s yearly salary again.
Page 2 of 2 PAPER REF. NO
Note: Encapsulation requires you to hide your data, while you expose the behaviours

9) Consider the following classes and arrange them into an inheritance hierarchy:

10) Implement a code to find the largest element from an arbitrary linear array.

You might also like