The following code is poorly structured: Rewrite it so that it has a better structure and avoids
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 user always types 1 or 2. (How would the code need to be modified to handle any number that the user might type?)
Transcribed Image Text:
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;
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 88% (9 reviews)
Refactored code to reduce redundancy If the user could typ...View the full answer
Answered By
Mustafa olang
Please accept my enthusiastic application to solutionInn. I would love the opportunity to be a hardworking, passionate member of your tutoring program. As soon as I read the description of the program, I knew I was a well-qualified candidate for the position.
I have extensive tutoring experience in a variety of fields. I have tutored in English as well as Calculus. I have helped students learn to analyze literature, write essays, understand historical events, and graph parabolas. Your program requires that tutors be able to assist students in multiple subjects, and my experience would allow me to do just that.
You also state in your job posting that you require tutors that can work with students of all ages. As a summer camp counselor, I have experience working with preschool and kindergarten-age students. I have also tutored middle school students in reading, as well as college and high school students. Through these tutoring and counseling positions, I have learned how to best teach each age group. For example, I created songs to teach my three-year-old campers the camp rules, but I gave my college student daily quizzes to help her prepare for exams.
I am passionate about helping students improve in all academic subjects. I still remember my excitement when my calculus student received her first “A” on a quiz! I am confident that my passion and experience are the qualities you are looking for at solutionInn. Thank you so much for your time and consideration.
4.80+
2+ Reviews
10+ Question Solved
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Question Posted:
Students also viewed these Computer science questions
-
What is wrong with the following code fragment? Rewrite it so that it produces correct output.
-
The following code is not robust against invalid user input. Describe how to change the code so that it will not proceed until the user has entered a valid age and grade point average (GPA). Assume...
-
The following code is a slightly modified version of actual code that was in the Microsoft Zune music player in 2008. The code attempts to calculate todays date by determining how many years and days...
-
Draw a simple undirected graph G that has 12 vertices, 18 edges, and 3 connected components.
-
A heat pump receives heat from a lake that has an average winter time temperature of 6°C and supplies heat into a house having an average temperature of 23°C. (a) If the house loses heat to...
-
Modify the program from exercise 8 to use double instead of int. Also, make a vector of doubles containing the N1 differences between adjacent values and write out that vector of differences. Data...
-
A sheet of water of uniform thickness \((h=0.01 \mathrm{~m})\) flows from the device shown in Fig. P5.64. The water enters vertically through the inlet pipe and exits horizontally with a speed that...
-
The management of Hoyt Corp. is considering the effects of various inventory-costing methods on its financial statements and its income tax expense. Assuming that the price the company pays for...
-
Discuss the role of human factors in hazard analysis. How do techniques like Human Reliability Analysis (HRA) contribute to understanding and mitigating risks associated with human errors in...
-
A manufacturing firm has collected information on the number of defects produced each day for the past 50 days. The data have been described by the accompanying Minitab box-and-whisker plot. a. What...
-
Write the method called printTriangleType referred to in Self-Check Problem 25. This method accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of...
-
Write a method called longestName that accepts a Scanner for the console and an integer as parameters and prompts for names, then prints the longest name (the name that contains the most characters)...
-
When preparing the financial statements for the year ended October 31, accrued salaries owed to employees for October 30 and 31 were overlooked. The accrued salaries were included in the first salary...
-
What are the four stages of team formation?
-
Describe three benefits of sharing FYI messages with colleagues.
-
Why is it important to use an objective, easy-to-read style in a report?
-
How is refutation different from concession? Describe the circumstances in which you would use one over the other.
-
Explain a team situation in which you experienced conflict. What was the purpose of the team? Why did the affective and/or cognitive conflict occur? How did the team resolve the conflict? What was...
-
Particle 1 has a mass of m 1 = 3.6 x 10 - 6 kg, while particle 2 has a mass of m 2 = 6.2 x 10 -6 kg. Each has the same electric charge. These particles are initially held at rest, and the...
-
Consider a game of poker being played with a standard 52-card deck (four suits, each of which has 13 different denominations of cards). At a certain point in the game, six cards have been exposed. Of...
-
Repeat Exercise R-14.28 for Figure 14.10 that illustrates a BFS traversal. Repeat Exercise Describe the meaning of the graphical conventions used in Figure 14.9 illustrating a DFS traversal. What do...
-
Repeat Exercise R-14.28 for Figure 14.8 that illustrates a directed DFS traversal. Repeat Exercise Describe the meaning of the graphical conventions used in Figure 14.9 illustrating a DFS traversal....
-
In the merge-sort tree shown in Figures 12.2 through 12.4, some edges are drawn as arrows. What is the meaning of a downward arrow? How about an upward arrow? Figures 12.2 Figures 12.4 85 24 45 17 31...
-
Estimate the final temperature in Celsius of the combination if I drop 5 rolls of pennies at 2 0 C ( each roll is 5 0 pennies stacked together; assume they are pure copper ) into a cup of recently -...
-
A 100 gram mass is hung of then end of a cantilever beam . The beam is made of brass, and is 30 cm long (), 2 cm wide, and 3 mm thick. Find the resulting deflection ()
-
The nitrogen-vacancy (NV) and silicon-vacancy (SiV) defects in diamond can lead to many exciting quantum nanotechnologies in physical and biological sciences, including single-photon sensors,...
Study smarter with the SolutionInn App