COMP103P 0
COMP103P Applied Software Development
Late Summer Assessment Coursework for In-Class Test component
(20% of module mark)
Answer ALL questions
Submit answers in a pdf file by email to graham.roberts@ucl.ac.uk
Submission Deadline: Noon Wednesday August 15th 2018
1. Consider this UML class diagram:
a)
i) Class Employee has this constructor:
public Employee(String name, String address)
Write a Java version of the class.
[4 marks]
ii) An Employee object is immutable. Explain what this means and why
immutable objects are useful.
[3 marks]
b)
i) Class Location and its method addEmployee are both abstract. Write a
Java version of class Location assuming it has this constructor:
public Location(String name)
[4 marks]
ii) Explain what an abstract class is and the role of an abstract method.
[3 marks]
COMP103P 1
c) A room has a capacity that determines the maximum number of employees
that can be allocated to work in the room. The free capacity is the number of
employees that can be added if the room is not full.
Write a Java version of class Room assuming it has this constructor:
public Room(int capacity)
Assume all employees have unique names.
[8 marks]
d) Write a Java version of class OfficeBuilding assuming it has this
constructor:
public OfficeBuilding(String name)
The addEmployee method should add an employee to a room with available
capacity and return true. If no room is available, it should return false. The
findEmployeeRoom method should return the room where an employee is
allocated or null if no employee can be found. Assume all employees have
unique names.
[10 marks]
e) Describe how an instance object of class Room might be tested. You are not
required to write a test class but should list the tests needed.
[8 marks]
[Total 40 marks]
COMP103P 2
2.
a) Explain each of the following:
overloading, overriding, binding, final method
[3 marks each, sub-total of 12 marks]
b) A class SortedStringQueue stores a queue of Strings in sorted ascending
order (lowest value first). The class has the following methods:
• A constructor to create an empty queue.
• A method get that removes and returns the string at the front of the
queue. The method throws an exception if the queue is empty.
• A method add that adds a string to the queue, such that the queue
remains sorted.
• A method size that returns the current length of the queue.
• A method isEmpty that returns true if the queue is empty.
i) Write a Java version of the class.
[10 marks]
ii) Write a class SortedStringQueueException to be used with the
get method.
[4 marks]
iii) Show how a queue object is created and used, providing an example of
how each method is called.
[4 marks]
[Total 30 Marks]
COMP103P 3
3.
a) Method parameters are passed by value. Explain what this means.
[4 marks]
b) Consider the statements:
double d = 1;
int n = 4/1.0;
State whether each statement is valid or not, and if not explain why.
[4 marks]
c) Give the Java code needed to declare and create a 10x10x10 array of
integers and initialise each array element to 5.
[6 marks]
d) Given two variables, a and b, of type MyClass, explain what happens
when the statements below are evaluated:
if (a == b) {…}
if (a.equals(b)) {…}
[6 marks]
e) Consider this recursive method:
public static void g(int i, int j)
{
if (i < j)
{
System.out.print(i + " ");
i++;
g(i,j);
}
}
Give the output of the following method calls:
g(5,5), g(4,5), g(3,5), g(2,5), g(1,5),
g(0,6).
Describe what algorithm the method implements.
[10 marks]
[Total 30 marks]
END
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。