



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The instructions and questions for a bachelor's exam in computing in information technology at cork institute of technology. The exam covers various topics in java programming, including object-oriented concepts, file i/o, sorting arrays, and creating applets. Students are required to write code snippets and answer theoretical questions.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




(NFQ Level 7)
Instructions Answer FOUR questions
Examiners: Mr. G. Mac Sweeney Mr. J. Greenslade Mr. J. Walsh
Q1. (a) Write the code to define the class Person() which includes code for the following
methods:
(b) Write a program to create an array of ten Person() objects and read ten names
and ages into the array from the file people.dat.
The first part of the code is as follows:
import java.io.*; public class Test1 { public static void main( String args[] ) throws IOException {
File f = new File("people.dat"); FileInputStream fs = new FileInputStream(f); InputStreamReader isr; BufferedReader fileInput; isr = new InputStreamReader(fs); fileInput = new BufferedReader(isr); ……. (8 Marks)
(c) Write a piece of code which sorts the items from the array into order the youngest first. (9 Marks)
Q2. (a) Java is an object-orientated language. Name another. (2 Marks)
(b) State some of the reasons why some developers were unhappy with functional languages. (4 Marks)
(c) State the main advantages of object-orientated languages. (6 Marks) (d) State any disadvantages of object-orientated languages. (3 Marks)
(e) What is polymorphism? (2 Marks) (f) How does polymorphism manifest itself in Java? (3 Marks) (g) What is meant by encapsulation? (2 Marks)
(h) What is UML (Unified Modelling Language)? (3 Marks)
Q3. Write an applet which prompts a user to enter dimensions for a room. The program
should calculate the volume of the room when the button is clicked.
The interface might look like the following:
(25 Marks)
Q5. (a) Write a method for a PrimeNumbers() class which determines if a given
positive integer is a prime number. (8 Marks) (b) Using this method, write a program that lists all prime numbers within a given range
e.g. if the range is between 1 and 12 the output might look something like the following:
1 true 2 true 3 true 4 false 5 true 6 false 7 true 8 false 9 false 10 false 11 true 12 false (9 Marks)
(c) Write a program that determines whether a Sting is a palindrome i.e. a word or
expression that spells the same way backwards as forwards e.g. navan. A sample output might look like this:
navan is a palindrome
cork is not a palindrome (8 Marks)
Q6. (a) In Java, what is meant by association? (2 Marks)
(b) Write a Job() class with the following attributes, constructor and methods:
attributes: responsibility, payRate, time
constructor: public Job(String responsibility, double payRate, double time)
methods: public double getPayRate() public double getTime() public String getResponsibility() (6 Marks)
(c) Write an Employee() class with the following attributes, constructor and methods:
attributes: name, newJob
constructor: public Employee(String name, Job newJob)
methods: private String displayName() private double calculatePay() public void displayDetails() (6 Marks)
(d) Write an example program which incorporates the above classes. (6 Marks)
(e) In java, what is a Vector()? (2 Marks) (f) Suggest an advantage of using Vector() instead of an array? (3 Marks)