Dear Learners,
Sincere apologies for the gap in Coding Posts! This post is also like apologies and warning from the Employee to the Organization!
Problem Statement
You are working on a program to evaluate the compliance of employees with the company's Work From Office (WFO) policy. The policy states that employees must work from the office for at least 3 days per week and a minimum of 12 days per month. Additionally, the program should track the number of Work From Home (WFH) days and print which specific week(s) do not satisfy the policy.
Input
- The program should read a list of integers where each integer represents the number of WFO days in a week for a given month.
- The list will always contain exactly 4 integers, representing the 4 weeks in a month.
- Each integer will be in the range
[0, 5]
, representing the number of WFO days in a week (since there are 5 working days in a week).
Output
- Calculate the total number of WFO days and WFH days for each week and for the entire month.
- Determine the compliance level based on the following criteria:
- If the total WFO days per month are less than 12 or any week has fewer than 3 WFO days:
- If only one week is non-compliant, print "Yellow warning".
- If two weeks are non-compliant, print "Orange warning".
- If three weeks are non-compliant, print "Red warning".
- If all four weeks are non-compliant, print "Suspension: If non-compliance continues next month, automatic notice period will be served."
- Print the total number of WFH days for each week and identify which specific week(s) do not satisfy the policy.
Example
Task
Write a Java program to determine the compliance level based on the given WFO days per week, calculate the total number of WFH days, and identify which specific week(s) do not satisfy the policy. Implement the program to read the input, perform the necessary calculations, and print the required output.
SOLUTION:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class WorkFromOfficeCompliance {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Integer> wfoDaysPerWeek = new ArrayList<>();
System.out.println();
for (int i = 0; i < 4; i++) {
wfoDaysPerWeek.add(scanner.nextInt());
}
scanner.close();
int totalWFODays = 0;
int totalWFHDays = 0;
List<Integer> nonCompliantWeeks = new ArrayList<>();
for (int i = 0; i < 4; i++) {
int wfoDays = wfoDaysPerWeek.get(i);
int wfhDays = 5 - wfoDays;
totalWFODays += wfoDays;
totalWFHDays += wfhDays;
if (wfoDays < 3) {
nonCompliantWeeks.add(i + 1);
}
}
System.out.println("Total WFO days this month: " + totalWFODays);
System.out.println("Total WFH days this month: " + totalWFHDays);
if (totalWFODays < 12 || nonCompliantWeeks.size() > 0) {
if (nonCompliantWeeks.size() == 1) {
System.out.println("Week " + nonCompliantWeeks.get(0) + ": WFO days insufficient (" + wfoDaysPerWeek.get(nonCompliantWeeks.get(0) - 1) + " days)");
System.out.println("Yellow warning");
} else if (nonCompliantWeeks.size() == 2) {
for (int week : nonCompliantWeeks) {
System.out.println("Week " + week + ": WFO days insufficient (" + wfoDaysPerWeek.get(week - 1) + " days)");
}
System.out.println("Orange warning");
} else if (nonCompliantWeeks.size() == 3) {
for (int week : nonCompliantWeeks) {
System.out.println("Week " + week + ": WFO days insufficient (" + wfoDaysPerWeek.get(week - 1) + " days)");
}
System.out.println("Red warning");
} else if (nonCompliantWeeks.size() == 4) {
for (int week : nonCompliantWeeks) {
System.out.println("Week " + week + ": WFO days insufficient (" + wfoDaysPerWeek.get(week - 1) + " days)");
}
System.out.println("Suspension: If non-compliance continues next month, automatic notice period will be served.");
}
}
}
}
- The program uses
Scanner
to read input from the user. It expects 4 integers representing the number of Work From Office (WFO) days for each week in a month. - It uses an
ArrayList<Integer>
namedwfoDaysPerWeek
to store the WFO days for each week. - It calculates
totalWFODays
which is the sum of WFO days across all weeks in the month. It also calculatestotalWFHDays
as the sum of Work From Home (WFH) days based on 5 working days per week. - Non-compliance Detection - It identifies weeks where the number of WFO days is less than 3 and stores these weeks in the
nonCompliantWeeks
list. - It prints the total number of WFO days and WFH days for the month using
System.out.println()
. - Compliance Check - It checks if the total WFO days for the month are less than 12 or if there are any non-compliant weeks (
nonCompliantWeeks.size() > 0
). Based on this check, it prints warnings or suspensions. - Warning Levels: Depending on the number of non-compliant weeks (
nonCompliantWeeks.size()
), it prints different warning levels: - Yellow warning for one non-compliant week.
- Orange warning for two non-compliant weeks.
- Red warning for three non-compliant weeks.
- Suspension message if all four weeks are non-compliant.
- It iterates over
nonCompliantWeeks
to print specific messages for each non-compliant week, indicating how many WFO days were recorded. - The program follows a sequential flow where it first reads input, calculates totals and compliance, then prints outputs accordingly.
Comments
Post a Comment