




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
A past exam for the higher certificate in science in computing in information technology program at the cork institute of technology. The exam covers topics such as java programming, software development, linked lists, binary trees, and file input/output. It includes four questions with code examples and diagrams, and students are required to write java code, draw diagrams, and modify existing code. The exam also includes an appendix with code snippets for mylinkedlist, treenode, and student classes.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Instructions: Examiners: Mr. Jim Doyle Answer question 1 and any two others. Mr. J. Greenslade Mr. J. Walsh
a) Write a Java program that accepts the sales of each employee in turn and displays the salary for that individual.
The Program should stop when -1 is input for sales.
Use any method of input and output you like. You do not have to cater for the case where a user does not enter data correctly.
(25 marks)
b) Modify the program in part ( a) so that it prints the average sales for the entire sales force. That is the total of all sales divided by the number of sales that were input. Use an if-statement to avoid division by zero.
(5 marks)
a) Each Node in a binary tree can be thought of as a sub tree.
Using the TreeNode code in APPENDIX II, write the recursive method, insert(int d).
( 15 marks )
b) If an object implements Comparable then it can be sorted in any java.util.Collection.
Modify the Student code in APPENDIX III so that it implements Comparable or Comparable
Student s should be compared by their mark s.
( 10 marks )
c) Modify the TreeNode code from APPENDIX II including the code from part (a) of this question so that the tree will hold Students from part (b).
( 10 marks )
a) If ReadList is a class with two attributes:-
public static int size = 100; public Integer[] array = new Integer[size]; ,
Write Java code for the ReadList class, that reads Integers from the file “MyList” and stores them in array.
You may assume that the array is full of zeros to start with and that there are less than 100 Integers in the file. I.e. when reading from the file, you need to check that the data is read but not that the array is out of bounds.
Show all the code required from declaring the InputStreams up to closing the file.
( 20 marks )
b) Write a method for class ReadList in part (a) that sorts array in ascending order.
( 15 marks )
class TreeNode { int data;
TreeNode left; TreeNode right;
public TreeNode( int d) { data = d; left = null ; right = null ; }
public TreeNode() { data = 0; }
public void insert( int d) …
}
class Student { private int mark; private String name;
//constructor public Student(String n, int m) { mark = m; name = n; }
public void setMark(int m) { mark = m; } public void setName(String n) { name = n; } public int getMark() { return mark; } public String getName() { return name; }
}