关于后端:1902159251你知道几个

39次阅读

共计 8137 个字符,预计需要花费 21 分钟才能阅读完成。

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]

  1. 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]
  2. 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
  3. 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]
  4. 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]
  5. Design Patterns
    Consider the following code
  6. public class myClass {
  7. private static myClass instance ;
    3
  8. private myClass () {}
    5
  9. public static myClass getInstance () {
  10. if(instance == null) {
  11. instance = new myClass () ;
  12. }
  13. return instance ;
  14. }
  15. }
    (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
  16. Logging and Orthogonality
    Consider the following codea
  17. Logger logger = Logger . getLogger (“new logger “) ;
  18. Appender appender = new ConsoleAppender (new SimpleLayout () ,
    ConsoleAppender . SYSTEM_OUT ) ;
  19. logger . addAppender (appender) ;
  20. logger . setLevel (Level . DEBUG) ;
  21. logger . error (” error (1) “) ;
  22. logger . info (” info (1) “) ;
  23. logger . warn (” warn (1) “) ;
  24. logger . debug (” debug (1) “) ;
  25. logger . setLevel (Level . ERROR) ;
  26. logger . error (” error (2) “) ;
  27. logger . debug (” debug (2) “) ;
  28. logger . setLevel (Level . INFO) ;
  29. logger . warn (” warn (2) “) ;
  30. 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.
  31. 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.
  32. public class mainClass {
  33. public int add (int x , int y) {return x + y ;}
    3
  34. public int sub (int x , int y) {return x – y ;}
    5
  35. public int divide (int x , int y) {return x / y ;}
    7
  36. // save the results in a text file
  37. public void save (int values) throws IOException {
  38. PrintWriter out = new PrintWriter (” results . txt”) ;
  39. out . println (values) ;
  40. out . close () ;
  41. }
  42. } // end of class
    Question 7 Continued Over. . .
    Page 5 of 10 CoS
    . . . Question 7 Continued:
  43. public class smellyClass {
  44. public static void main (String [] args ) throws Exception {
  45. foo1 () ;
  46. foo2 () ;
  47. foo3 () ;
  48. }
    7
  49. // access methods in class mainClass and perform some arithmetic
    operations
  50. public static void foo1 () throws IOException {
  51. int results = 0;
  52. int x = 20;
  53. int y = 15;
    13
  54. mainClass mc = new mainClass () ;
  55. int r1 = mc . add (x , y) ;
  56. int r2 = mc . sub (x , y) ;
  57. int r3 = mc . divide (x , y) ;
  58. results = r1 + r2 + r3 ;
  59. mc . save (results) ;
  60. }
    21
  61. // same as foo1 , but with different numbers
  62. public static void foo2 () throws IOException {
  63. int results = 0;
  64. int x = 40;
  65. int y = 30;
    27
  66. mainClass mc = new mainClass () ;
  67. int r1 = mc . add (x , y) ;
  68. int r2 = mc . sub (x , y) ;
  69. int r3 = mc . divide (x , y) ;
  70. results = r1 + r2 + r3 ;
  71. mc . save (results) ;
  72. }
    35
  73. // take input from users , and save the summation in a text file
    as foo1 , but with different numbers
  74. public static void foo3 () throws IOException {
  75. Scanner i = new Scanner (System . in) ;
  76. int c = 10;
  77. int d = 20;
    41
  78. if (c > d) {
  79. System . out . print (” integer : “) ;
  80. int a = i . nextInt () ;
    45
  81. System . out . print (” integer : “) ;
  82. int b = i . nextInt () ;
  83. mainClass mc = new mainClass () ;
    49
  84. mc . save (mc . add (a , b) ) ;
  85. }
  86. }
  87. }
    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
  88. Metrics and Testing
    Consider the following main production class (Search) which implements a fibonacci
    search algorithma
    :
  89. public class Search {
  90. public static int fibonacciSearch (int [] integers , int
    elementToSearch ) {
    3
  91. int fibonacciMinus2 = 0;
  92. int fibonacciMinus1 = 1;
  93. int fibonacciNumber = fibonacciMinus2 + fibonacciMinus1 ;
  94. int arrayLength = integers . length ;
    8
  95. while (fibonacciNumber < arrayLength) {
  96. fibonacciMinus2 = fibonacciMinus1 ;
  97. fibonacciMinus1 = fibonacciNumber ;
  98. fibonacciNumber = fibonacciMinus2 + fibonacciMinus1 ;
  99. } // end of while loop
    14
  100. int offset = -1;
    16
  101. while (fibonacciNumber > 1) {
  102. int i = Math . min (offset + fibonacciMinus2 , arrayLength – 1)
    ;
  103. if (integers [ i] < elementToSearch ) {
  104. fibonacciNumber = fibonacciMinus1 ;
  105. fibonacciMinus1 = fibonacciMinus2 ;
  106. fibonacciMinus2 = fibonacciNumber – fibonacciMinus1 ;
  107. offset = i ;
  108. } else if (integers [ i] > elementToSearch ) {
  109. fibonacciNumber = fibonacciMinus2 ;
  110. fibonacciMinus1 = fibonacciMinus1 – fibonacciMinus2 ;
  111. fibonacciMinus2 = fibonacciNumber – fibonacciMinus1 ;
  112. } else
  113. return i ;
  114. }// end of while loop
    31
  115. if (fibonacciMinus1 == 1 && integers [ offset + 1] ==
    elementToSearch ) {
  116. return offset + 1; }
  117. return -1;
  118. }// end of method
  119. }
    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:
  120. class SearchTest {
  121. private final Search search = new Search () ;
  122. int [] listOfNumbers = {1 ,3 ,10 ,21 ,77 ,400 ,401};
    4
  123. @Test
  124. void testFirstElement () {
  125. int result = search . fibonacciSearch (listOfNumbers ,1) ;
  126. assertEquals (0 , result) ;}
    9
  127. @Test
  128. void testLastElement () {
  129. int result = search . fibonacciSearch (listOfNumbers ,401) ;
  130. assertEquals (6 , result) ;}
    14
  131. @Test
  132. void testOutOfBoundary () {
  133. // create an out of boundary value and test the value
  134. // insert your code here
  135. }
    20
  136. @Test
  137. void testUnsortedArray () {
  138. // create an unsorted array (int []) and test if the results
    would still be valid or invalid
  139. // insert your code here
  140. }
  141. }
    (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
  142. 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
正文完
 0