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
QUESTION 1 Someone may choose to own a car instead of leasing because: AThe car can be resold later to make some money back. BTh
Lorico [155]
This is not a computers and technology question but ill still answer it and the answer to this that i think it is ...A ...but i may be wrong
3 0
3 years ago
Is it possible for the front and rear references in a circular array implementation to be equal?
azamat

Answer:

Yes it is possible for the following cases:-

  1. When the queue is full.
  2. When the queue is empty.

Explanation:

When the queue is full the the front and the rear references in the circular array implementation are equal because after inserting an element in the queue we increase the rear pointer.So when inserting the last element the rear pointer will be increased and it will become equal to front pointer.

When the queue is empty the front and rear pointer are equal.We remove an element from queue by deleting the element at front pointer decreasing the front pointer when there is only one element and we are deleting that element front and rear pointer will become equal after deleting that element.

7 0
3 years ago
1. Problem solving is
Ne4ueva [31]

Answer:

A

Explanation:

1. Problem solving is

(4 Points)

O A. highly interactive

B. collaborative

C. Both And B

D. Designing an App

4 0
3 years ago
When you break an iPad, can you recover an iMovie?
kompoz [17]
Yes, on your cloud. you should have an email 

7 0
3 years ago
Read 2 more answers
An operating system coordinates the BLANK of a computers operation.
devlian [24]
I believe it is D. The Central Processing Unit (CPU) can manage memory and storage. It also makes sure every program has what it needs to keep it up and running. 
8 0
3 years ago
Read 2 more answers
Other questions:
  • Melinda completed the Computer Programming Aptitude Test when she applied for a position with Beta Electronics. Six months later
    12·1 answer
  • True or False? In C++, the expression (a + b / c) / 2 is implicitly parenthesized as ((a + b) / c) / 2.
    9·1 answer
  • ________ is the standard communications protocol used on most client/server networks.
    9·1 answer
  • You are planning trip to South America and and are worried about your devices with private keys being stolen. So you decide to s
    9·1 answer
  • The purpose of validating the results of the program is Group of answer choices To create a model of the program To determine if
    12·1 answer
  • Text and graphics that have been out of copied are stored in area called the _____
    15·2 answers
  • Who is the father of computer?​
    6·1 answer
  • The the concept of plug-and-play is demonstrated by which of the following scenarios
    14·2 answers
  • The specific instructions that a computing device needs to boot up and control the hardware
    12·1 answer
  • Why is it important to enforce access controls and to keep logs regarding who has access to data closets
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!