The following Java 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. public void spending(Scanner console,String name) { System.out.print("How much will " + name + " be spending?"); double amount = console.nextDouble(); System.out.println(); int numBills = (int) (amount / 20.0); if (numBills * 20.0 < amount) { numBills++; } System.out.println(name + " needs " + numBills + " bills"); } The code above is all I was given to work with, which is why I'm a bit confused and need help. Thank you.
The following Java 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.
public void spending(Scanner console,String name)
{
System.out.print("How much will " + name + " be spending?");
double amount = console.nextDouble();
System.out.println();
int numBills = (int) (amount / 20.0);
if (numBills * 20.0 < amount)
{
numBills++;
}
System.out.println(name + " needs " + numBills + " bills");
}
The code above is all I was given to work with, which is why I'm a bit confused and need help. Thank you.
Step by step
Solved in 3 steps with 1 images