Document 280323

Important notice: This document is a sample exam. The final exam will differ from
this exam in numerous ways. The purpose of this sample exam is to provide students
with access to an exam written in a similar style and with a similar structure to their final
exam. Both this sample exam and the final exam sample material from the entire
semester, but the selection will be different in the final exam to what is presented here.
INTRODUCTION TO SOFTWARE SYSTEMS
(COMP1110/COMP1140/COMP1510/COMP6710)
Writing period: 3 Hours duration
Study period: 15 Minutes duration
Permitted materials: None
You must attempt to answer all questions.
Questions are not of equal value.
All questions must be completed on this exam paper.
This examination paper must not be taken out of the exam room.
Student ID: _______________________
Course Code: _______________________
Please do not write in the grey boxes that appear throughout the exam paper. These are for use by markers.
Q1
Q2
/10
Q3
/10
Q4
/35
Q5
/20
Q6
/15
/10
/100
Page 1 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
Question 1. [10 Marks] Imperative Programming
Given the following code:
im po rt java.util.ArrayList;
im po rt java.util.List;
pu bl ic cl as s Simple {
pr iv at e st at ic String foo(in t i) {
String result = "";
if (i < 2)
re tu rn result + i;
el se {
fo r (in t j = i; j >0; j--) {
result += j;
}
re tu rn result + foo(i-1) + foo(i-2);
}
}
pu bl ic st at ic vo id main(String[] args) {
List<Integer> list = ne w ArrayList<Integer>();
list.add(1);
list.add(2);
list.set(0, 0);
System.out.println("A: "+list);
list.remove(1);
System.out.println("B: "+list);
System.out.println("C: "+list.get(0));
System.out.println("D: "+foo(3));
}
}
Note: The toString() method of ArrayList will print in the format [ 1, 2, 3 ] (for a list
of 1, 2, and 3).
Write in the box below exactly what the program will output when it is run.
Q1
/10
Page 2 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
Question 2. [10 Marks] Multiple choice
Read the following carefully: Given the following 15 True/False questions, mark either
True or False (but not both). Each question that is correctly answered gains you 1 mark, each
question answered incorrectly loses you 1 mark, a question left unanswered neither loses nor
gains marks. The final mark for this question is calculated by bounding the sum of marks
between 0 and 10.
For example, if you answered all questions correctly you would gain 10 (not 15) for this
question. If you answer 8 correctly, 2 incorrectly and leave the remaining 5 unanswered you
would gain 6/10 for this question.
If you wish to change your answer then cross off both True and False and clearly state your
answer in words. (e.g. “I would like to leave this question unanswered.” or “My answer is
True.”)
Basic Java
c)
An if statement must
a) true || false is equal to true.
b) ((int) 2.4) / 2 is equal to 1.2.
always be followed by an else statement.
True  False 
True  False 
True  False 
Object Oriented Programming
d) A Java class can inherit from multiple classes.
e) An object is an instantiation of a class.
f) An Interface cannot include method implementations.
g) Anonymous inner classes are useful for passing code to methods.
True 
True 
True 
True 
Abstract Data Types
h) A binary search tree can be used to implement a set.
i) A linked list is an efficient way to implement a map.
j) An array can be used to implement a list.
True  False 
True  False 
True  False 
Complexity
k) Finding an element in a well-designed hash table is O(1).
l) Finding an element in a linked list is O(Log N) .
True  False 
True  False 
Software Engineering
m) Test driven development begins with a test that fails.
n) A mercurial changeset that has two children indicates a branch.
o) Formal verification is important for safety critical software.
True  False 
True  False 
True  False 
False 
False 
False 
False 
Q2
/10
Page 3 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
Question 3 [35 Marks] Software development
This question concerns a small piece of software for keeping track of stock in a grocery store.
The software will reduce stock each time stock is sold, increase stock each time new stock
arrives, and correct stock levels every time a careful count is made of the actual stock on the
store’s shelves (this activity is called a ‘stock take’). Each item for sale is called a product.
Every product has: a string that uniquely identifies it called a stock-keeping unit or SKU (e.g.
‘473C2D’); a target stock level, a current stock level; and a name, a human-readable string
that describes it (e.g. ‘Vegemite, 500g’, or ‘Apple, Granny Smith’). There are two
categories of item: unit items and bulk produce. Unit items are sold by count (e.g. 2 jars of
jam), and stock is counted in units. Bulk items are sold by weight (e.g. 450g of apples), and
stock is counted in kilograms (and may be fractions). Your client is a grocer who has asked
you to write software that has the following public interface:
p ub l ic i n te r fa c e St o ck M an a ge r {
/**
* A new product has been introduced
* @param sku The product’s sku
* @param name The product’s name
* @param price The product’s price (per unit for units or per kg for bulk)
* @param bulk True if the item is a bulk item, false if it is a unit item
*/
p ub l ic vo id newItem(S tr i ng sku, S tr i ng name, d ou b le price, b oo l ea n bulk);
/**
* An product has been sold; reduce current stock accordingly.
* @param sku The product’s sku
* @param sold The quantity sold
*/
p ub l ic vo id sale(S tr i ng sku, d ou b le sold);
/**
* New stock has arrived; increase current stock accordingly.
* @param sku The product’s sku
* @param added The quantity newly arrived
*/
p ub l ic vo id addStock(S tr i ng sku, d ou b le added);
/**
* Set the target amount of stock for a product.
* @param sku The item’s sku
* @param target The target quantity desired to be held in stock
*/
p ub l ic vo id targetStock(S tr i ng sku, d ou b le target);
/**
* Stock has been carefully counted. Set current stock correctly.
* @param sku The product’s sku
* @param actual The quantity actually in the store
* @return The stock loss or gain (new current – old current)
*/
p ub l ic d ou b le stockTake(S tr i ng sku, d ou b le actual);
/**
* Print one line for each item in the store with the SKU, the name,
* and the amount needed to reach the target stock level.
*/
p ub l ic vo id printOrderReport();
}
Page 4 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
3 i) [10 Marks]
In the space below, draw a UML class diagram for your class MyStockManager (which
implements the StockManager interface), and any other classes that your class will depend
on, excepting those classes that are part of the standard Java library (e.g. String, etc).
/10
Page 5 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
3 ii) [5 Marks]
In the space below, write a declaration of MyStockManager, including all of its fields, but
excluding all methods. This should be consistent with the UML diagram for the class in 3i).
/5
3 iii) [5 Marks]
In the space below, write an implementation of the newItem() method.
p ub l ic v o id newItem(S tr i ng sku, S tr i ng name, d ou b le price, b oo l ea n bulk) {
/5
}
3 iv) [5 Marks]
In the space below, write an implementation of the sale() method.
p ub l ic v o id sale(S tr i ng sku, d ou b le sold) {
/5
}
Page 6 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
3 v) [5 Marks]
In the space below, write a unit test for the sale() method from 3 iv).
@Test
p ub l ic v o id saleTest() {
/5
}
3 vi) [5 Marks]
In the space below, write an implementation of the printOrderReport() method.
p ub l ic v o id printOrderReport() {
/5
}
Q3
/35
Page 7 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
Question 4. [20 Marks] Abstract data types
Consider the following skeleton implementation of a simple list ADT based on an array.
public class ArrayList<V> {
static final int INITIAL_SIZE = 4;
static final double GROWTH_FACTOR = 1.5;
int elements = 0; // the number of elements in our list
V[] values = (V[]) new Object[INITIAL_SIZE];
/**
* Add a value to the tail of the list.
* @param value The value to be added.
*/
public void add(V value) {
/* unimplemented */
}
/**
* Remove the value at the specified index from the list.
* @param index
*/
public void remove(int index) {
/* unimplemented */
}
/**
* @param index
* @return The value at the specified index.
*/
public V get(int index) {
if (index >= elements || index < 0)
throw new IndexOutOfBoundsException();
return values[index];
}
/**
* Reverse the order of the elements of the list.
*/
public void reverse() {
/* unimplemented */
}
}
Page 8 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
4 i) [7 Marks]
In the space below, provide an implementation of the missing add(V value) method.
/7
4 ii) [7 Marks]
In the space below, provide an implementation of the missing remove(int index) method.
/7
Page 9 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
4 iii) [6 Marks]
In the space below, provide an implementation of the missing reverse() method.
/6
Q4
/20
Page 10 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
Question 5 [15 Marks] Threads, Complexity, and Grammars
5 i) [5 Marks]
Describe a situation in which a race condition is likely to arise.
/5
5 ii) [5 Marks]
Discuss the computational complexity of using a linked list to implement a set. Use big-O
notation in your answer.
/5
5 iii) [2 Marks]
Define an EBNF grammar for four-digit binary numbers (e.g. 1010, 1111, 0001, 1000, etc).
/2
5 iv) [3 Marks]
Define an EBNF grammar for dates, in the format dd/mm/yy (e.g. 02/11/12, 31/10/11 etc).
/3
Q5
/15
Page 11 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
Question 6 [10 Marks]
You must answer only one of 6a) or 6b), choosing according to your degree program.
6 a) (COMP1110, COMP1140, COMP6710 students only)
Use the space below to discuss the strengths and weaknesses of Java as a general purpose
programming language. Your discussion should contain five major points that you clearly
identify. Draw comparisons with other languages where appropriate.
6 b) (COMP1510 students only)
In 1996, a $500M Ariane rocket self-destructed on launch. A report concluded that ‘a
program segment for converting a floating point number to a signed 16 bit integer was
executed with an input data value outside the range representable by a signed 16 bit
integer.’ Use the space below to discuss what lessons this incident offers software
engineers. Your discussion should structured around five clearly identified major points.
Please circle your degree program: COMP1110 COMP1140 COMP1510 COMP6710
Q6
/10
Page 12 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
You may use this box as extra space for completing answers to previous questions.
Please indicate clearly which question(s) you are continuing.
Q1
Q2
Q3
Q4
Q5
Q6
Page 13 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )
You may use this box as extra space for completing answers to previous questions.
Please indicate clearly which question(s) you are continuing.
Q1
Q2
Q3
Q4
Q5
Q6
Page 14 of 14 - INTRODUCTION TO SOFTWARE SYSTEMS – ( COMP1110/COMP1140/COMP1510/COMP6710 )