The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a method named spending that accepts two parameters: a Scanner for the console, and a String for a single person's name, and prints the appropriate information about that person's bills. Your method could be called twice (once for John and once for Jane) to replicate the original code's behavior.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter4: Making Decisions
Section: Chapter Questions
Problem 8E: In the game Rock paper Scissors, two players simultaneously choose one of three options: rock,...
icon
Related questions
Question
100%

The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a method named spending that accepts two parameters: a Scanner for the console, and a String for a single person's name, and prints the appropriate information about that person's bills. Your method could be called twice (once for John and once for Jane) to replicate the original code's behavior.

1 Scanner console = new Scanner (System.in);
2 System.out.prínt("How much will John be spending? "):
3 double amount = console.nextDouble%;
4 System.out.println();
5 int numBills1 = (int) (amount / 20.0);
6 if (numBills1 * 20.0 < amount) {
%D
7
numBills1++3;
8)
9 System.out.print("How much will Jane be spending? ");
10 amount = console.nextDouble();
11 System.out.println();
12 int numBills2 = (int) (amount / 20.0);
13 if (numBills2 * 20.0 < amount) {
14
15 }
numBills2++;
16 System.out.println("John needs
17 System.out.println("Jane needs
+ numBills1 + " bills");
+ numBills2+
bills");
Transcribed Image Text:1 Scanner console = new Scanner (System.in); 2 System.out.prínt("How much will John be spending? "): 3 double amount = console.nextDouble%; 4 System.out.println(); 5 int numBills1 = (int) (amount / 20.0); 6 if (numBills1 * 20.0 < amount) { %D 7 numBills1++3; 8) 9 System.out.print("How much will Jane be spending? "); 10 amount = console.nextDouble(); 11 System.out.println(); 12 int numBills2 = (int) (amount / 20.0); 13 if (numBills2 * 20.0 < amount) { 14 15 } numBills2++; 16 System.out.println("John needs 17 System.out.println("Jane needs + numBills1 + " bills"); + numBills2+ bills");
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT