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>
- public static void main(String[] args) {
-
- int hourlyWage = 20;
- int workHoursPerWeek = 35;
- int workWeeksPerYear = 52;
- int annualSalary = 0;
-
- annualSalary = hourlyWage * workHoursPerWeek * workWeeksPerYear;
- System.out.print("Annual salary is: ");
- System.out.println(annualSalary);
-
- System.out.print("Monthly salary is: ");
- System.out.println((hourlyWage * workHoursPerWeek * workWeeksPerYear) / 12);
-
- return;
-
- }
Program output:
Annual salary is: 36400
Monthly salary is: 3033
<u>Revised Program after introducing monthly salary</u>
- public static void main(String[] args) {
-
- int hourlyWage = 20;
- int workHoursPerWeek = 35;
-
- int workWeeksPerYear = 52;
- int annualSalary = 0;
- int monthlySalary = 0;
-
- annualSalary = hourlyWage * workHoursPerWeek * workWeeksPerYear;
- monthlySalary = hourlyWage * workHoursPerWeek * workWeeksPerYear;
-
- System.out.print("Annual salary is: ");
- System.out.println(annualSalary);
-
- System.out.print("Monthly salary is: ");
- System.out.println((monthlySalary) / 12);
-
- return;
-
- }
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.
No it is not a good idea, it shouldn’t
be memberwise assignment NOT be used when an object contains a pointer to
dynamically allocated memory. Class members are private by
default, the following describes a class that would be a good candidate
for conversion to a template class is a class which defines a new type of array.
Công nghệ đã thay đổi cách mọi người sử dụng để giao tiếp ở nơi làm việc hiện đại
Answer:
Please check the attachment,
Explanation:
Please check the attachment.
Answer:
See Explanation
Explanation:
<em>See attachment for complete question</em>
The programming language is not stated; I'll answer using Python and Java
Python:
low = 56
high = 70
for i in range(low,high+1):
print(i)
Java:
public class PrintOut{
public static void main(String [] args)
{
int low = 56; int high = 70;
for(int i = low; i<=high;i++)
System.out.print(i+" ");
}
}
For both codes, the explanation is:
The code starts by initializing the range of the print out to 56 and 70
Next, the code segment used an iteration that loops through 56 and 70 and print each digit in this range (both numbers, inclusive).