diff --git a/src/Time/Test.class b/src/Time/Test.class index fef20e3..15bbe19 100644 Binary files a/src/Time/Test.class and b/src/Time/Test.class differ diff --git a/src/Time/Test.java b/src/Time/Test.java index ccd22b1..40f6c6a 100644 --- a/src/Time/Test.java +++ b/src/Time/Test.java @@ -2,7 +2,7 @@ import java.util.Scanner; public class Test{ public static void main(String [] args){ - Time t = new Time(12, 50, "am"); + Time t = new Time(11, 00, "am"); Time t2 = new Time(1, 1, "pm"); Scanner sc = new Scanner(System.in); diff --git a/src/Time/Time.class b/src/Time/Time.class index f567d21..6156d75 100644 Binary files a/src/Time/Time.class and b/src/Time/Time.class differ diff --git a/src/Time/Time.java b/src/Time/Time.java index 9360b37..52c5812 100644 --- a/src/Time/Time.java +++ b/src/Time/Time.java @@ -53,10 +53,18 @@ public class Time{ return null; } + private boolean isMidday(){ + return h==12 && id.equals("pm"); + } + + private boolean isMidnight(){ + return h==12 && id.equals("am"); + } + public int toMinute(){ - if(id.equals("pm")) + if((id.equals("pm") && !isMidday()) || isMidnight()) h+=12; - return h*60+m; + return (h*60+m)%(24*60); } public boolean isAfter(Time t){ @@ -71,7 +79,11 @@ public class Time{ int totm=this.toMinute() + m%(24*60); this.m=totm%60; this.h=(totm/60)%24; - if(this.h>12){ + if(this.h==0){ + this.h+=12; + }else if(this.h==12){ + this.id="pm"; + }else if(this.h>12){ this.id="pm"; this.h-=12; }else @@ -79,14 +91,7 @@ public class Time{ } public void shift(int h, int m){ - int totm=this.toMinute() + (m+h*60)%(24*60); - this.m=totm%60; - this.h=(totm/60)%24; - if(this.h>12){ - this.id="pm"; - this.h-=12; - }else - this.id="am"; + shift(h*60+m); }