EECS2030E Test 4

Tuesday November 15, 2016, 16:00-17:20
Lab 02
Version E

Instructions

There is one programming question and a set of short answer questions.

Instructions for submitting your programming question solution are given in the Programming question section. You may submit as many times as you want; your most recent submission will be the one recorded.

Instructions for submitting your answers to the short answer questions are given in the Short Answer Questions section. You may submit as many times as you want; your most recent submission will be the one recorded.

Programming question

Implement this API. A skeleton can be found here here. The JAR file for this test can be found here. The skeleton compiles, but the constructors are not implemented and the methods do not return the correct values; you should complete the constructors and methods to satisfy their APIs. The provided code does not provide any fields; you must decide what fields are required by your implementation.

For reference: the Java API is here.

Submit your program using the following command in a terminal (make sure you are in the directory containing your file Temperature.java):

submit 2030 test4E ItemizedBill.java


Short Answer Questions

Question 1

What is the main advantage of using composition over aggregation? (Be concise in your answer; try to use no more than one sentence.)


Question 2

Suppose that a method header states that it throws an exception of type X:

public void someMethod() throws X

If a child class overrides the method, what types of exceptions can the child class version of the method throw?

A. any type that is a child of Exception
B. any type that is a child of RuntimeException
C. any type that is a child of X
D. any type that is a parent of X

Question 3

Examine your implementation of getItems and the provided implementation of getSortedItems in the class ItemizedBill.

Does getSortedItems contain a privacy leak? Using no more than three sentences, explain your answer.




Enter your answers into a text file named answers.txt. You can use the editor of your choice for this. You can also create a text file in Eclipse by selecting "New" and then "Untitled Text File" in the "File" menu. Make sure that you save your file. Also make sure that you indicate which question you are answering, e.g. Q1: answer to question 1 Q2: answer to question 2 Q3:...

Submit your answers using the following command in a terminal (make sure you are in the directory containing your file answers.txt):

submit 2030 test4E answers.txt