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]
3 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]3 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
"The ______ of an operational system that supports an organization includes policies, requirements, and conditional statements t
Serggg [28]

Answer:

decision logic

Explanation:. The decision logic of an operational system that supports an organization includes policies, requirements, and conditional statements that govern how the system works. These systems includes the following :

a) Order processing,

b)Pricing

c) Inventory control, and

d) Customer relationship management. And the traditional means of modifying the decision logic of information systems involves heavy interaction between business users and information technology (IT) analysts.

3 0
3 years ago
Which of the following should NOT be done to keep people from slipping on floors? A) Have the proper absorbents in an easy-to-fi
RoseWind [281]

The following options helps keep people from slipping on floors

A) Have the proper absorbents in an easy-to-find place to quickly put on spills : So that accidental little spills can be cleaned right away.

C) Wear slip-resistant footwear : It is a precautionary step to follow, no matter where we go.

D) Mark a slippery area with an easy-to-use tent sign that says " Caution, Slippery floor" : This allows people to be aware of the wet area and cross it cautiously.

Leaving oil and fluids to air dry thoroughly, takes a long time and there are chances that people step over it and slip.

So, the answer is

(B) Anytime oil or fluids are spilled on the floor, leave them to thoroughly air dry.

8 0
3 years ago
Read 2 more answers
Can someone help me with this
Alex787 [66]
I’m not sure but I think it belongings.
5 0
3 years ago
In which of the following scenarios would you use the Redo function?
MakcuM [25]
D. <span>You have just used the Undo function to delete a paragraph, and you want that paragraph back.</span>
6 0
3 years ago
What is the term used for the initial document that includes the necessary information to build a game?
arlik [135]

Game design document is the term used for the initial document that includes the necessary information to build a game

Explanation:

A game design document serves as a nexus and core to combine and list all features of a game. It consists of written descriptions, images, graphs, charts and lists of data relevant to specific parts of improvement, and is usually formed by what characteristics will be in the game, and sets out how they will all fit together.

Creating a GDD will assist the team's designer in knowing what the fragrance of the game is and the intended range of its overarching world. Holding all the game factors in one well-organized document will help the designer easily communicate their idea to the rest of the team, and also healing to pinpoint deficiencies or missing components of the game. The GDD should serve as your master checklist.

4 0
3 years ago
Other questions:
  • A network engineer is configuring a network to be able to relay IPv6 packets. The network only supports IPv4 and does not have d
    11·1 answer
  • P**nhub or x-videos or other
    9·1 answer
  • What class of attacks use innovative attack tools and once a system is infected it silently extracts data over an extended perio
    6·1 answer
  • Whitch action should a user take to ensure that formatting is applied to a row? A. use the ctrl+a keys. B. highlight the whole t
    11·1 answer
  • Create a SavingsAccount class. Use a static data member annualInterestRate to store the annual interest rate for each of the sav
    10·1 answer
  • The multitasking, multi-user, operating system developed by Bell Laboratories that operates on a wide variety of computing platf
    13·1 answer
  • Which types of scenarios would the NETWORKDAYS function help calculate? Check all that apply.
    7·1 answer
  • Implement a recursive method named power that takes 2 integer parameters named base and expo. The method will return the base ra
    6·1 answer
  • Imagine a machine that produces an output force that is five times larger
    11·1 answer
  • Commercial technical data and commercial software:_________.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!