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