Question
Consider the following code: int f(int[] a, int[] b) { int sum = 0; for (int i = 0; i < a.length; i++) sum +=a[i];
Consider the following code:
int f(int[] a, int[] b) { int sum = 0;
for (int i = 0; i < a.length; i++) sum +=a[i]; for (int j = 0; j < b.length; j++) sum +=b[j]; returnsum;
}
a. Which code smellis present in this code? (Choose exactly one.)
[ ]duplicatecode [ ] long parameterlist [ ]longmethod [ ]none
b. Which refactoring would you choose to eliminate the smell (Choose exactlyone.)
[ ]extractmethod [ ] introduce parameterobject [ ] replace method withmethodobject [ ] nonerequired
c. What will the code look like after the refactoring (ifrequired):
Step by Step Solution
3.44 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
a The code smell present in this code is duplicate code becaus...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Computer Organization And Design The Hardware Software Interface
Authors: David A. Patterson, John L. Hennessy
4th Revised Edition
0123747503, 978-0123747501
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App