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
The presentation ____ determines the formatting characteristics of fonts and colors.
Alex Ar [27]
The presentation theme determines the formatting characteristics of fonts and colors.
4 0
4 years ago
Refer to the exhibit, a technician applies the configuration in the exhibit to an unconfigured router. To verify the configurati
pentagon [3]

Answer:

E. Enable secret 5 $1$v0/3$QyQWmJyT7zCa/yaBRasJm0 enable password 7 14141E0A1F17 line console 0 password 7 020507550A

Explanation:

The cisco ios is the operating system of any cisci network device. It is a command line interface used to configure these cisco devices.

The privilege user command "show running-config" in the command line interface is used to show the current configuration on the RAM of the router.

There are two ways to protect the router's console line with a password, with enable secret and enble password. The "enable secret" is a slightly encrypted password but the "enable password" has no encryption. These password methods are used to secure any channel to the router.

The "service password-encryption" command is used to encrypt all the passwords in the current configuration, to prevent attackers or unauthorized users from getting to the router.

7 0
4 years ago
As more and more computing devices move into the home environment, there's a need for a centralized storage space, called a ____
Ksivusya [100]

Answer: Network attached storage device

Explanation:

Network attached storage(NAS) is the data storage server device that is responsible for serving files to configuration and other components.Through this sever device data can be retrieved by various client and user from central disk capacity .It provides good data access to diverse user and client of data.

  • Other options are incorrect because RAID drive, server station, gigabit NIC are not the devices that centrally store huge amount of data for access.
  • Thus, the correct option is network attached storage(NAS) device

8 0
3 years ago
The ____ is a new feature in versions of microsoft office, starting with office 2007; it consists of tabs, which contain groups
lions [1.4K]
Excel i think that's correct
5 0
4 years ago
All of the following are advantages of database-stored information, except: Question 3 options: 1) Reduced information redundanc
enot [183]

Answer:

3) Reduced information integrity.

Explanation:

This is not an advantage, Information integrity is a key factor when storing information on a database. As multiple users will access it, they will need this data to be authentic and dependable. Any reduction in information integrity is a great disadvantage.

5 0
3 years ago
Other questions:
  • When troubleshooting firewalls, which of the following is not something you should do after you attempt a fix?
    7·1 answer
  • How do smart watches affect the business and its position in the global marketplace?
    12·2 answers
  • What are the best apps to learn coding
    15·2 answers
  • The index finger on your right hand types the _____.
    11·1 answer
  • Which of the following lists contains the five essential elements of a computer?
    5·1 answer
  • Write the header for a function addOne that accepts a single integer reference parameter and returns nothing. Name the parameter
    5·1 answer
  • arlos, an algebra teacher, is creating a series of PowerPoint presentations to use during class lectures. After writing, formatt
    12·2 answers
  • WILL GIVE BRAINLIEST!!!!
    14·2 answers
  • My chrome book computer clock is an hour off how do I fix that
    14·1 answer
  • Write a function named count_vowels that accepts two arguments: a string and an empty dictionary. The function should count the
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!