Computer Science Assignment: Code Analysis and Software Design

Verified

Added on  2019/09/21

|5
|676
|187
Homework Assignment
AI Summary
This assignment solution addresses several aspects of software development and design. It includes solutions for test case creation, specifically for condition and path coverage, along with code examples. The assignment analyzes the concepts of divergent change and shotgun surgery, explaining their differences. The solution also provides a truth table and refactored code based on the given conditions. Furthermore, it discusses potential issues that can arise during method renaming, such as naming conflicts. Finally, it illustrates the conversion of inheritance to delegation using a Stack class example, showing how to create a field and delegate methods to a superclass object to avoid inheritance. The document includes images to visually represent inheritance and delegation.
Document Page
Question 2)
1. public static void main(string args[]){
2. float x,y; int a,b;
3. read(x);
4. read(y);
5. if((x == 0) ||(y>0))
6. y = y/x;
7. else x = y+2;
8. system.out.println(x);
9. system.out.println(y);
10. call addition(a,b);
11. }
12. Public void addition(int a, int b){
13. System.out.println(a+b);
14. }
1. Set of test cases for the condition coverage
Test Case 1: x = 0 y = 2s // true
Test Case 2: x = 5 y = -2 // false
2. Set of test cases for the path coverage
Test Case: a = 10 b = 20
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Document Page
Question 3)
Ans a): Divergent change seems like Shotgun Surgery but there is a little difference. Divergent
Change is followed when there are many changes are to made in a single class whereas Shotgun
Surgery refers to when a single change is to made in multiple classes simultaneously.
Ans b):
(A & B & C)
F
T F
T T F
T T T
(A & B & ! C)
F
T F
T T !T = (F)
T T !F = (T)
(A & !B & C)
F
T !T = F
T !F = T F
T !F = T T
(A & !B & !C)
F
T !T = F
T !F = T !T = F
T !F = T !F = T
Document Page
(!A & B & C)
!T = F
!F = T F
!F = T T F
!F = T T T
(!A & B & !C)
!T = F
!F = T F
!F = T T !T = F
!F = T T !F = T
(!A & !B & C)
!T = F
!F = T !T = F
!F = T !F = T F
!F = T !F = T T
(!A & !B & !C)
!T = F
!F = T !T = F
!F = T !F = T !T = F
!F = T !F = T !F = T
Upgraded Code:
If (A & B & C) then Result = Action1
Else Result = Action0
If (A & B & !C) then Result = Action1
If (A & !B & C) then Result = Action1
If (A & !B & !C) then Result = Action1
If (!A & B & C) then Result = Action1
If (!A & B & !C) then Result = Action0
If (!A & !B & C) then Result = Action0
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
The existing code is replaced by new design of code.
Ans c:
It could be a reason that when we renaming a method with new name
but we forget that this new name is already used (It could be
variable name, method name) this will create a big problem in code.
Ans d:
Class Stack is extending Vector class.
I have a child class that uses only one portion of the methods of
its superclass.
So to convert inheritance to delegation a field is created and this
is uses a superclass object in it, delegate methods to the parent
class object to avoid inheritance.
Image one: showing inheritance
Image two: showing delegation
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon