Computers and Technology

Fix the code in oops2.java so that it is better structured and avoids redundancy. there are some lines of code that are repeated. think about where you can move the repeated lines in the code so that they only appear once. you do not need to add any error checking on the user input, assume that the user will always enter 1 or 2. here is the code: import java. util. scanner; public class oops2 {public static void main(string[] args) { int sum = 0; int count = 0; int total = 0; 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; count++; total = total + sum; } if (times == 2){ system. out. println("and how much are you contributing? "); int donation = console. nextint(); sum = sum + 2 * donation; count++; total = total + sum; } system. out. println("the total is " + total); }}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:10, reycaden
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
image
Computers and Technology, 24.06.2019 05:50, 11232003
What all vehicles has tesla inc. created over the years
Answers: 3
image
Computers and Technology, 24.06.2019 12:50, vianca15
What percentage of teens plays video games? a.97% b.100% c.74% d.50%
Answers: 1
image
Computers and Technology, 24.06.2019 19:20, boyancecristina
Which command suppresses the visibility of a particular row or column in a worksheet?
Answers: 1
Do you know the correct answer?
Fix the code in oops2.java so that it is better structured and avoids redundancy. there are some lin...

Questions in other subjects:

Konu
Computers and Technology, 17.07.2019 08:10
Konu
Mathematics, 17.07.2019 08:10
Konu
Mathematics, 17.07.2019 08:10
Konu
Biology, 17.07.2019 08:10
Konu
Chemistry, 17.07.2019 08:10