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
Lelu [443]
3 years ago
12

The following program uses a variable workHoursPerWeek rather than directly using 40 in the salary calculation expression.

Computers and Technology
1 answer:
Serjik [45]3 years ago
7 0

Answer:

<u> Initial program output (from original program)</u>

Annual salary is: 40000

Monthly salary is: 3333

<u>Program output after workHoursPerWeek = 35</u>

Annual salary is: 35000

Monthly salary is: 2916

<u>Revised program (using variable workWeeksPerYear)</u>

  1.    public static void main(String[] args) {
  2.        int hourlyWage = 20;
  3.        int workHoursPerWeek = 35;
  4.        int workWeeksPerYear = 52;
  5.        int annualSalary = 0;
  6.        annualSalary = hourlyWage * workHoursPerWeek * workWeeksPerYear;
  7.        System.out.print("Annual salary is: ");
  8.        System.out.println(annualSalary);
  9.        System.out.print("Monthly salary is: ");
  10.        System.out.println((hourlyWage * workHoursPerWeek * workWeeksPerYear) / 12);
  11.        return;
  12.    }

Program output:

Annual salary is: 36400

Monthly salary is: 3033

<u>Revised Program after introducing monthly salary</u>

  1.    public static void main(String[] args) {
  2.        int hourlyWage = 20;
  3.        int workHoursPerWeek = 35;
  4.        int workWeeksPerYear = 52;
  5.        int annualSalary = 0;
  6.        int monthlySalary = 0;
  7.        
  8.        annualSalary = hourlyWage * workHoursPerWeek * workWeeksPerYear;
  9.        monthlySalary = hourlyWage * workHoursPerWeek * workWeeksPerYear;
  10.        
  11.        System.out.print("Annual salary is: ");
  12.        System.out.println(annualSalary);
  13.        System.out.print("Monthly salary is: ");
  14.        System.out.println((monthlySalary) / 12);
  15.        return;
  16.    }

Explanation:

One reason to use variable to replace the magic number is to improve the readability of the program. If we compared the revised version of the program with the original program, we will find that the variable enable our code easier to understand.

Besides, if we wish to change the value (e.g. working hours per year or per month), we just need to adjust the value assigned on the variables. The variables provide a single access point to get or change the value.

You might be interested in
Data in the form of digits is called
Flauer [41]
Numeric data because it consist of numbers
5 0
2 years ago
Descuss the five generations of Computer language
Fiesta28 [93]

Answer:

Explanation:

The programming language in terms of their performance reliability and robustness can be grouped into five different generations, First generation languages (1GL) Second generation languages (2GL) Third generation languages (3GL)

6 0
3 years ago
What is a grant cycle?
Lina20 [59]

Answer:

The grant lifecycle refers to the entire process a grant goes through—from creating the opportunity through implementation and ending with the closeout.

Explanation:

... The grant lifecycle is comprised of three distinct phases: Pre-Award, Award, and Post Award. Hope that this helps you and have a great day :)

5 0
3 years ago
Read 2 more answers
In the Mouse Properties window, you can
levacccp [35]
B- You can adjust the mouse's double-click speed.

Some computer mouse software (depends on brand) will allow you to set new tasks for the mouse to perform.  Sometimes there are mice that have extra buttons that can be programmed to do certain tasks.
6 0
4 years ago
Most nosql data stores were created to address problems associated with storing large amounts of distributed data in __________.
finlep [7]
NoSQL is primarily designed for supporting the decision making systems. Most NoSQL data stores were created to address problems associated with storing large amounts of distributed data in relational database management systems(RDBMS).
RDBMS is system used for the management of the database.D<span>ata is stored in the form of related tables.</span>
3 0
4 years ago
Other questions:
  • What is this I’m so lost
    9·1 answer
  • Question 4 / 5
    11·1 answer
  • What component of a processor holds instructions waiting to be processed by the alu?
    11·1 answer
  • Design a program that asks the user to enter a string containing a series of single digit numbers with nothing separating them.
    7·1 answer
  • How should work be allocated to the team in a Scrum project?
    13·1 answer
  • An instruction for the computer. Many commands put together to
    5·1 answer
  • There are some games that cannot be described by a single--or even two-- genres. Can you think of any that should be invented?​
    6·1 answer
  • How to call a variable as a tag in react native.
    12·1 answer
  • Most scheduling algorithms maintain a run queue, which lists processes eligible to run on a processor. On multicore systems, the
    10·1 answer
  • What is the action of extracting data fragments and then reassembling them in order to recover a file?.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!