Advertisement
coasterka

#ExamSchedule

Jun 11th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamSchedule {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         Scanner scan = new Scanner(System.in);
  8.        
  9.         int startHour = scan.nextInt();
  10.         int startMins = scan.nextInt();
  11.         String partOfDay = scan.next();
  12.         int durationHours = scan.nextInt();
  13.         int durationMins = scan.nextInt();
  14.        
  15.         int endHour = startHour + durationHours;
  16.         int endMins = startMins + durationMins;
  17.        
  18.         switch (partOfDay) {
  19.         case "PM":
  20.             if (endMins > 59) {
  21.                 endMins = endMins % 60;
  22.                 endHour ++;
  23.             }
  24.             if (endHour >= 12) {
  25.                 endHour = endHour % 12;
  26.                 if (endHour == 0 || endHour == 24) {
  27.                     endHour = 12;
  28.                 }
  29.                 partOfDay = "AM";                  
  30.             }
  31.             break;
  32.         case "AM":
  33.             if (endMins > 59) {
  34.                 endMins = endMins % 60;
  35.                 endHour++;
  36.             }
  37.             if (endHour >= 12) {
  38.                 endHour = endHour % 12;
  39.                 if (endHour == 0 || endHour == 24) {
  40.                     endHour = 12;
  41.                 }
  42.                 partOfDay = "PM";
  43.             }
  44.         }
  45.         System.out.printf("%02d:%02d:%s", endHour, endMins, partOfDay);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement