Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Modular_Decomposition
- {
- /*Established the main class as type void. Then initializes variable hour of integer type to 0, variable hoursPerDay also of integer type to 24,
- also initializes the variable name hoursPerHalfDay with the value of 12 in integer data type. Then, I started a while loop that runs as long
- as the hour is less than the number of hours per day (24). Each time the loop runs the value of hour is incremented up one, the method printHour,
- Report, Checkpoint, Extract, and Upload are called. Lastly, a new line is printed using System.out.print and the new line key "\n".
- */
- public static void main(String[] args)
- {
- int hour = 0;
- int hoursPerDay = 24;
- int hoursPerHalfDay = 12;
- while(hour < hoursPerDay)
- {
- hour++;
- printHour(hour, hoursPerHalfDay, hoursPerDay);
- Report(hour);
- Checkpoint(hour);
- Extract(hour);
- Upload(hour);
- System.out.print("\n");
- }
- }
- /* **The printHour method** The variables hour, hoursPerHalfDay, and hoursPerDay are called in the method header. I then created an if statement
- that will run only if the value of hour is less than the value of hoursPerHalfDay. In this if statement the value of hour is concatenated with
- the string " AM", and then ended. Then, there is an else if statement that only occurs when the value of hour is equal to the value of hoursPerHalfDay.
- When this condition is met, the value of hour is concatenated with the string " PM". Then another else if is made. This time the condition is
- when both hour is greater than hoursPerHalfDay (12) and less than hoursPerDay (24). When these two things occur, the value of hour minus 12 is
- concatenated with the string " PM". Then the last else if condition is made. The condition for this one is when the value of hour equals hoursPerDay.
- When this condition is met, the value of hour minus 12 is concatenated with the sting " AM".
- */
- public static void printHour(int hour, int hoursPerHalfDay, int hoursPerDay)
- {
- if(hour < hoursPerHalfDay)
- {
- System.out.print(hour + " AM");
- }
- else if(hour == hoursPerHalfDay)
- {
- System.out.print(hour + " PM");
- }
- else if(hour > hoursPerHalfDay && hour < hoursPerDay)
- {
- System.out.print((hour - 12) + " PM");
- }
- else if(hour == hoursPerDay)
- {
- System.out.print((hour - 12) + " AM");
- }
- }
- /* ***The Report Method*** The variable hour is called in this method. Then, an if statement is created with the condition being if hour equals 8, 12,
- or 18 then "tab tab Report tab |" will be printed. If this condition is not met, the catch all "else" will print out tab tab tab tab | to keep the
- correct alignment.*/
- public static void Report(int hour)
- {
- if(hour == 8 || hour == 12 || hour == 18)
- {
- System.out.print("\t \t Report \t |");
- }
- else
- {
- System.out.print("\t \t \t \t |");
- }
- }
- /* ***The Checkpoint Method*** The variable hour is called in this method. Then, an if statement is created with the condition being that
- hour equals 4, 8, 12, 16, 20, or 24. If this condition is met, "tab Checkpoint tab |" will be printed. If the condition is not met else it will
- fall under else and "tab tab tab |" will be printed.*/
- public static void Checkpoint(int hour)
- {
- if(hour == 4 || hour == 8 || hour == 12 || hour == 16 ||
- hour == 20 || hour == 24)
- {
- System.out.print("\t Checkpoint \t |");
- }
- else
- {
- System.out.print("\t \t \t |");
- }
- }
- /* ***The Extract Method*** The variable hour is called in this method. Then, an if statement is created with the condition of hour being
- equal to 8 or 21. When this condition is met, "tab Extract tab |" is printed. If this condition is not met, "tab tab tab 1\" is printed.
- */
- public static void Extract(int hour)
- {
- if(hour == 8 || hour == 21)
- {
- System.out.print("\t Extract \t |");
- }
- else
- {
- System.out.print("\t \t \t |");
- }
- }
- /* ***The Upload Method*** The variable hour is called in this method. Then, an if statement is created with the condition of hour being
- equal to 11 or 20. If this condtion is met "tab Upload tab|" is printed. If the condition is not met "tab tab tab |" is printed.
- */
- public static void Upload(int hour)
- {
- if(hour == 11 || hour == 20)
- {
- System.out.print("\t Upload \t |");
- }
- else
- {
- System.out.print("\t \t \t |");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement