The following code is poorly structured: 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...



The following code is poorly structured:


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;


count1++;


total = total + donation;


}


if (times == 2) {


System.out.print("And how much are you contributing? ");


int donation = console.nextInt();


sum = sum + 2 * donation;


count2++;


total = total + donation;


}


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?)



May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here