1902/159.251
MTUI DISD
MASSEY UNIVERSITY
MANAWAT¯U AND DISTANCE CAMPUSES
EXAMINATION FOR
159.251 Software Engineering Design and Construction
SEMESTER TWO 2019
Time allowed is THREE (3) hours.
All students are required to answer ALL questions.
There are 9 questions altogether.
Total marks: 52.
Write your answers in the Blue Answer Book supplied.
All relevant working must be shown to gain full marks.
Students may NOT remove any part of this question paper from the exam room.
The exam paper will be made available on the University Library website.
Page 1 of 10 CoS
Short Answers
[23 marks]
- Version control and versioning
(a) Explain how a normal git workflow works in practice. Use examples (git
command) in your answer. (2 marks)
(b) Git branches are regularly used in projects. Explain how they work into a
team’s git workflow and the best practice usage for them. (2 marks)
[4 marks] - Build tools and process automation
(a) Explain the role of build tools such as Maven in the software development
process. Use an example of how Maven helps with automating tasks. (2
marks)
(b) Diamond dependencies occur when two dependencies both depend on a third
project but at a different version. Explain why this is a problem in Java, using
the idea of classloaders. (1 marks)
(c) Explain what a Semantic Version is and how developers should adjust it when
making a new version release. (2 marks)
(d) Explain the pros and cons of choosing version ranges when declaring dependencies.
(1 mark)
[6 marks]
Page 2 of 10 CoS - Software Design and Architecture
Most application architectures employ a 3-tier model:
(a) Draw the components of this model and how they link to each other. (2 marks)
(b) Explain how Domain-Driven Design allows this model to function without
having large amounts of duplication across layers. (1 mark)
Coupling and Cohesion
(c) Define what the terms coupling and cohesion are. (2 marks)
(d) Explain their implications to project design and software quality. (1 mark)
(e) Explain how the Interface Segregation Principle (ISP) fits in with the idea of
coupling. (1 marks)
[7 marks] - Miscellaneous
(a) Assume you are working on a commercial project. You wish to choose a
dependency that will fulfil a specific need in your project. There are two
options, one dependency with a GPLv2 licence, and the other with a BSD
licence. Explain the legal implications of using each in your project. (3 marks)
(b) Explain the difference in the software workflow between teams using a traditional
waterfall software development methodology versus an agile methodology.
Choose one specific agile methodology and explain it in your example.
(3 marks)
[6 marks]
Page 3 of 10 CoS
Code Quality, Analysis and Refactoring
[29 marks] - Design Patterns
Consider the following code - public class myClass {
- private static myClass instance ;
3 - private myClass () {}
5 - public static myClass getInstance () {
- if( instance == null ) {
- instance = new myClass () ;
- }
- return instance ;
- }
- }
(a) Identify the design pattern used here. List the necessary features within the
code to implementing this design pattern. (3 marks)
(b) Explain the known pros and cons of using this pattern. Provide an example
of when we would want to use this design pattern. (2 marks)
[5 marks]
Page 4 of 10 CoS - Logging and Orthogonality
Consider the following codea - Logger logger = Logger . getLogger ("new logger ") ;
- Appender appender = new ConsoleAppender (new SimpleLayout () ,
ConsoleAppender . SYSTEM_OUT ) ; - logger . addAppender ( appender ) ;
- logger . setLevel ( Level . DEBUG ) ;
- logger . error (" error (1) ") ;
- logger . info (" info (1) ") ;
- logger . warn (" warn (1) ") ;
- logger . debug (" debug (1) ") ;
- logger . setLevel ( Level . ERROR ) ;
- logger . error (" error (2) ") ;
- logger . debug (" debug (2) ") ;
- logger . setLevel ( Level . INFO ) ;
- logger . warn (" warn (2) ") ;
- logger . debug (" debug (2) ") ;
What will be printed on the console if the following script is executed? (2 marks)
[2 marks]
aLogger, Appender, ConsoleAppender and Level are all classes in org.apache.log4j, the import
statement is omitted. - Code smells and Anti-patterns
Consider the following code (two classes, mainClass and smellyClass), which
works fine (no compilation issues). However, the program contains a number of
code smells that need to be refactored. - public class mainClass {
- public int add (int x , int y ) { return x + y ; }
3 - public int sub (int x , int y ) { return x - y ; }
5 - public int divide (int x , int y ) { return x / y ; }
7 - // save the results in a text file
- public void save (int values ) throws IOException {
- PrintWriter out = new PrintWriter (" results . txt") ;
- out . println ( values ) ;
- out . close () ;
- }
- } // end of class
Question 7 Continued Over. . .
Page 5 of 10 CoS
. . . Question 7 Continued: - public class smellyClass {
- public static void main ( String [] args ) throws Exception {
- foo1 () ;
- foo2 () ;
- foo3 () ;
- }
7 - // access methods in class mainClass and perform some arithmetic
operations - public static void foo1 () throws IOException {
- int results = 0;
- int x = 20;
- int y = 15;
13 - mainClass mc = new mainClass () ;
- int r1 = mc . add (x , y ) ;
- int r2 = mc . sub (x , y ) ;
- int r3 = mc . divide (x , y) ;
- results = r1 + r2 + r3 ;
- mc . save ( results ) ;
- }
21 - // same as foo1 , but with different numbers
- public static void foo2 () throws IOException {
- int results = 0;
- int x = 40;
- int y = 30;
27 - mainClass mc = new mainClass () ;
- int r1 = mc . add (x , y ) ;
- int r2 = mc . sub (x , y ) ;
- int r3 = mc . divide (x , y) ;
- results = r1 + r2 + r3 ;
- mc . save ( results ) ;
- }
35 - // take input from users , and save the summation in a text file
as foo1 , but with different numbers - public static void foo3 () throws IOException {
- Scanner i = new Scanner ( System . in ) ;
- int c = 10;
- int d = 20;
41 - if ( c > d ) {
- System . out . print (" integer : ") ;
- int a = i . nextInt () ;
45 - System . out . print (" integer : ") ;
- int b = i . nextInt () ;
- mainClass mc = new mainClass () ;
49 - mc . save ( mc . add (a , b ) ) ;
- }
- }
- }
Page 6 of 10 CoS
Question 7 Continued Over. . .
. . . Question 7 Continued:
(a) Identify the potential code smells in SmellyClass. Explain why these are
code smells and what damage they would potentially do if we left them in the
code. (3 marks)
(b) What refactoring recommendation(s) would you suggest here to improve the
code? Consider providing a short example of a refactoring recommendation
to one or two of the three methods. Answer this together with (c). (3 marks)
(c) Refactor code to be self-documenting using best practice (e.g., variable names,
comments etc..). Use the same answer (one code snippet) for both b and c.
(3 marks)
[9 marks]
Page 7 of 10 CoS - Metrics and Testing
Consider the following main production class (Search) which implements a fibonacci
search algorithma
: - public class Search {
- public static int fibonacciSearch (int [] integers , int
elementToSearch ) {
3 - int fibonacciMinus2 = 0;
- int fibonacciMinus1 = 1;
- int fibonacciNumber = fibonacciMinus2 + fibonacciMinus1 ;
- int arrayLength = integers . length ;
8 - while ( fibonacciNumber < arrayLength ) {
- fibonacciMinus2 = fibonacciMinus1 ;
- fibonacciMinus1 = fibonacciNumber ;
- fibonacciNumber = fibonacciMinus2 + fibonacciMinus1 ;
- } // end of while loop
14 - int offset = -1;
16 - while ( fibonacciNumber > 1) {
- int i = Math . min ( offset + fibonacciMinus2 , arrayLength - 1)
; - if ( integers [ i ] < elementToSearch ) {
- fibonacciNumber = fibonacciMinus1 ;
- fibonacciMinus1 = fibonacciMinus2 ;
- fibonacciMinus2 = fibonacciNumber - fibonacciMinus1 ;
- offset = i ;
- } else if ( integers [ i ] > elementToSearch ) {
- fibonacciNumber = fibonacciMinus2 ;
- fibonacciMinus1 = fibonacciMinus1 - fibonacciMinus2 ;
- fibonacciMinus2 = fibonacciNumber - fibonacciMinus1 ;
- } else
- return i ;
- }// end of while loop
31 - if ( fibonacciMinus1 == 1 && integers [ offset + 1] ==
elementToSearch ) { - return offset + 1; }
- return -1;
- }// end of method
- }
aFibonacci search is a technique of searching a sorted array using a divide and conquer algorithm
that narrows down possible locations with the aid of Fibonacci numbers.
Question 8 Continued Over. . .
Page 8 of 10 CoS
. . . Question 8 Continued:
The following is a test class (SearchTest) for the above algorithm: - class SearchTest {
- private final Search search = new Search () ;
- int [] listOfNumbers = {1 ,3 ,10 ,21 ,77 ,400 ,401};
4 - @Test
- void testFirstElement () {
- int result = search . fibonacciSearch ( listOfNumbers ,1) ;
- assertEquals (0 , result ) ;}
9 - @Test
- void testLastElement () {
- int result = search . fibonacciSearch ( listOfNumbers ,401) ;
- assertEquals (6 , result ) ;}
14 - @Test
- void testOutOfBoundary () {
- // create an out of boundary value and test the value
- // insert your code here
- }
20 - @Test
- void testUnsortedArray () {
- // create an unsorted array (int []) and test if the results
would still be valid or invalid - // insert your code here
- }
- }
(a) Calculate the following from the Search class (all subquestions) and
SearchTest class (for parts iii and iv):
i) Lines of code (physical - no comments). (1 mark)
ii) Cyclomatic complexity. (2 marks)
iii) Statement coverage. (1 mark)
iv) Branch coverage. (1 marks)
(b) Explain any deficiencies in the branch coverage results. (1 mark)
(c) Update the tests to increase the branch coverage (write the currently unimplemented
tests testOutOfBoundary and testUnsortedArray). (4 marks)
[10 marks]
Page 9 of 10 CoS - Process Automation and Continuous Integration
There is an existing Maven project with a local and remote git repository set up.
It has the following files which do not yet exist on the repositories:
.travis.yml
.gitignore
foo.java
bar.java
file1.jar
file2.jar
(a) Fill in the currently empty .travis.yml so that your Maven project will be
tested by Travis CI. (1 marks)
(b) Fill in the currently empty .gitignore file so that no JAR files get committed.
(1 marks)
(c) Write a sequence of git commands to make sure that the above files are included
in both your local and remote repositories. (1 mark)
[3 marks] -
-
-
-
-
-
- +
Page 10 of 10 CoS
- +
-
-
-
-
-