Lesson 3: Control Flow
Activity 6: Controlling the Flow of Execution Using Conditionals
Solution:
- Create a class named Salary and add main() method:
public class Salary {
public static void main(String args[]) {
- Initialize two variables workerhours and salary.
int workerhours = 10;
double salary = 0;
- In the if condition, check whether the working hours of the worker is below the required hours. If the condition holds true, then the salary should be (working hours * 10).
if (workerhours <= 8 )
salary = workerhours*10;
- Use the else if statement to check if the working hours lies between 8 hours and 12 hours. If that is true, then the salary should be calculated at $10 per hour for the first eight hours and the remaining hours should be calculated at $12 per hour.
else if((workerhours > 8) && (workerhours < 12))
salary = 8*10 + (workerhours - 8) * 12;
- Use the else block for the default of $160 (additional day's salary) per day.
else
salary = 160;
System...