1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aleksley [76]
4 years ago
14

The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate r

edundancy, 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.
Scanner console = new Scanner(System.in);
System.out.print("How much will John be spending? ");
double amount = console.nextDouble();
System.out.println();
int numBills1 = (int) (amount / 20.0);
if (numBills1 * 20.0 < amount) {
numBills1++;
}
System.out.print("How much will Jane be spending? ");
amount = console.nextDouble();
System.out.println();
int numBills2 = (int) (amount / 20.0);
if (numBills2 * 20.0 < amount) {
numBills2++;
}
System.out.println("John needs " + numBills1 + " bills");
System.out.println("Jane needs " + numBills2 + " bills");
Computers and Technology
1 answer:
Virty [35]4 years ago
7 0

Answer:

Explanation:

public static void main(String[] args) {

       Scanner console = new Scanner(System.in);

       spending(console,"John");  //calling spending method with "John"

       spending(console,"Jane");  //calling spending method with "Jane"

   }

   public static void spending(Scanner console, String name){

       System.out.print("How much will "+name+" be spending? ");

       double amount = console.nextDouble();

       System.out.println();

       int numBill = (int) (amount / 20.0);

       if (numBill * 20.0 < amount) {

           numBill++;

       }

       System.out.println("John needs " + numBill + " bills");

   }

Code Explanation

Method are reusable set of code which reduces redundancy. So the original code was trying to calculate the bill for John and Jane but the code to calculate was redundant which will cause more line of code and complex to manage. For example let say if we have 1000 of user to calculate there bill, will it be efficient to write bill calculation code for all 1000 users?

That's where function comes in to reduce redundancy from code and easy to manage.

Easy to Manage in a way, let say you need to change the bill calculation formula then without function, you have to change the formula for all the users but with function you only need to change the bill calculation formula in spending function.

You might be interested in
How many generations of computers languages have there been since the middle of the 20th century
Molodets [167]
<span>There are 4 computer language generations. First is the first generation language or 1GL, second is the second-generation languages or the 2GL, next is the third-generation languages or the 3GL, and the last is fourth-generation languages or the 4GL.</span>
4 0
3 years ago
Read 2 more answers
Write the definition of a function typing_speed, that receives two parameters. The first is the number of words that a person ha
m_a_m_a [10]

Answer:

The function code and the formula for the above question is listed below:

Explanation:

Function:

float typing_speed(int Number_of_words, int Time_in_seconds)

{

float time= Time_in_seconds/60;

float speed= Number_of_words/time;

return speed;

}

Formula for this algorithm or program:

Number of words per minute= number of words/ Time(in minutes).

Function Explanation

  • The above function defined in the c-language code, which is used to return the typing speed for any user when he enters the number of words and the time in seconds.
  • The speed is calculated with the help of the above-defined formula.
  • The first statement of the code is used to change the time in a minute.
  • The second statement of the code is used to calculate the speed by the help of speed formula.
  • Then the third statement returns the value of the speed variable.

6 0
3 years ago
Give example of a biometric authentication device​
seropon [69]

Finger Print Scanner, Spit Sample, Face ID

7 0
4 years ago
Ip address 10.10.20.0 255.255.255.224 how many host ip addresses are available in each subnet using this subnet mask?
Maksim231197 [3]
224 = 128 + 64 + 32, so that would mean each network could have 32 nodes. Subtract 2 for the network address and the multicast address, you would have 30 HOST addresses available.
3 0
4 years ago
Name all mario kart games in order
Juliette [100K]

Answer:

Super Mario Kart

Mario Kart 64

Mario Kart: Double Dash!!

Mario Kart 7

Mario Kart DS

Mario Kart: Super Circuit

Mario Kart Wii

Mario Kart 8

Mario Kart 8 Deluxe

Mario Kart Live: Home Circuit

Mario Kart

Mario Kart Arcade GP

Mario Kart Arcade GP 2

Mario Kart Tour

Mario Kart Arcade GP DX

Mario Kart Arcade GP VR

Super Mario 64

Super Mario 3D World

─▄████▄▄░

▄▀█▀▐└─┐░░

█▄▐▌▄█▄┘██

└▄▄▄▄▄┘███

██▒█▒███▀

5 0
3 years ago
Read 2 more answers
Other questions:
  • Suppose that the following regular expression is used to recognize real numbers in scientific notation in a programming language
    14·1 answer
  • Jessica has pinned her favorite applications as icons on her desktop. She always clicks on these icons to work on them. Which us
    5·1 answer
  • The Mail Merge option is located in which tab? a;home b;insert c;refernces d;mailings
    11·2 answers
  • What the best option if you cant show your PowerPoint presentation at all
    6·2 answers
  • What is the value stored at x, given the statements:
    11·1 answer
  • If the code for CAT is ECV what is the code for DOG? *
    9·2 answers
  • 12. How many different documents can<br> you have open at one time?
    8·1 answer
  • A Python keyword ______________.
    15·1 answer
  • PLEASE HELP URGENT!!
    5·2 answers
  • iv. Assuming the above operating system that cannot perform memory deallocation. Name at least three effects on the overall syst
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!