Question: The following code is poorly structured: Rewrite it so that it has a better structure and avoids redundancy. To simplify things, you may assume that
The following code is poorly structured:

Rewrite it so that it has a better structure and avoids redundancy. To simplify things, you may assume that the user always types 1 or 2. (How would the code need to be modified to handle any number that the user might type?)
int sum = 1000; Scanner console new Scanner (System.in); !! System.out.print ("Is your money multiplied 1 or 2 times? "); int times = console.nextInt (): if (times 1) { System.out.print ("And how much are you contributing? "); int donation = console.nextInt (); sum = sum + donation; countl++; total = total + donation; if (times 2) { %3D System.out.print ("And how much are you contributing? "); int donation = console.nextInt (); sum = sum + 2 * donation; count2++; total = total + donation;
Step by Step Solution
3.38 Rating (164 Votes )
There are 3 Steps involved in it
Refactored code to reduce redundancy If the user could typ... View full answer
Get step-by-step solutions from verified subject matter experts
