UCL Logo

Problem Class Questions 2006
for COMP1008 (Object-Oriented Programming)

Week 1 (Starting 16th January)

Questions 1-4 are about designing and writing methods, similar to questions that have appeared in past exams and tests. Question 5 looks at designing a complete program. Note, you do not need to use a computer at the lab class but try your code afterwards to see if it does actually work!

1. Write a method to reverse the order of the elements in an int array passed as a parameter (int[] reverse(int[] a)). For example, given an array containing [1,2,3,4,5,6], the method would return [6,5,4,3,2,1].

Which array does the method return? Does it reverse the array passed as the parameter or should it create and return a new array? Try both ways.

2. Write a method that takes two parameters, an array of integers and a single integer, and returns an array containing all the values in the parameter array that are a multiple of the integer parameter value. The array returned should not have any unused elements (i.e., it should be exactly the right size to hold the result or size zero if there are no multiples).

3a) Write a method that takes an integer parameter, separates the integer into its individual digits, and returns an array of the integers. For example, with a parameter value of 34567 the array [3,4,5,6,7] would be returned.

b) Do the same for a parameter of type double and return a 2D array, with the first row holding the digits before the decimal point and the second row holding the digits after the decimal point.

4. Write a method that takes two parameters, an array of integers and a single integer. The method should display the values in the array centred in a column of the width specified by the single integer parameter.

For example, the method call centreInColumn(array,width) where array is [2345, 3, 45, 123] and width is 8 would display:

   |  2345  |
   |    3   | 
   |   45   |
   |   123  | 

Visually the positioning is not perfect but represents the best that can be done given the way that characters are displayed. Determine the rules you will work to. Rather than write a single method it would be easier to write several methods for each step of the process, e.g., convert integer to characters, print one line, print the whole column.

5. Design a program to meet the following basic specification:

"A program is required to support a Helpdesk service. The program should allow for all calls to the service to be logged, assigned a priority and, if necessary, allocated to a technician for attention. A database of solutions to problems should be maintained, so that answers to common questions can be given immediately. The call priority should be used to schedule a response within set time limits, given the resources available. The end result of each call should also be recorded."

You need to turn this basic specification into a plausible set of requirements that you believe can be implemented as a program. In the absence of a real customer you will have to fill in the gaps and make decisions yourself about what is possible. For example, you will have to decide how problems are allocated to technicians and how technicians are booked, assuming you decide your program should actually take on those responsibilities.

Your program will need one ore more data structures (like an ArrayList) and a collection of methods to carry out the behaviour. You are not being asked to write the actual program code here but you need to be sure that your proposed design could actually be translated into working code.

Last updated: September 2, 2006

Computer Science Department - University College London - Gower Street - London - WC1E 6BT - Telephone: +44 (0)20 7679 7214 - Copyright 1999-2006 UCL


 Search by Google