diff --git a/src/Time/Test.class b/src/Time/Test.class new file mode 100644 index 0000000..fef20e3 Binary files /dev/null and b/src/Time/Test.class differ diff --git a/src/Time/Test.java b/src/Time/Test.java new file mode 100644 index 0000000..ccd22b1 --- /dev/null +++ b/src/Time/Test.java @@ -0,0 +1,16 @@ +import java.util.Scanner; + +public class Test{ + public static void main(String [] args){ + Time t = new Time(12, 50, "am"); + Time t2 = new Time(1, 1, "pm"); + Scanner sc = new Scanner(System.in); + + t.shift(sc.nextInt(), sc.nextInt()); + t.print(System.out); + if(t.isAfter(t2)) + System.out.println("t viene prima"); + else + System.out.println("t viene dopo"); + } +} diff --git a/src/Time/Time.class b/src/Time/Time.class new file mode 100644 index 0000000..f567d21 Binary files /dev/null and b/src/Time/Time.class differ diff --git a/src/Time/Time.java b/src/Time/Time.java new file mode 100644 index 0000000..9360b37 --- /dev/null +++ b/src/Time/Time.java @@ -0,0 +1,96 @@ +import java.io.PrintStream; +import java.util.Scanner; + +public class Time{ + + public Time(int h, int m, String id){ + this.h=h; + this.m=m; + this.id=id; + } + + public String getId(){ + return id; + } + + public int getH(){ + return h; + } + + public int getM(){ + return m; + } + + public void setId(String id){ + this.id=id; + } + + public void setH(int h){ + this.h=h; + } + + public void setM(int m){ + this.m=m; + } + + public void print(PrintStream ps){ + ps.println(h+" "+m+" "+id); + } + + public static Time read(Scanner sc){ + int h, m; + String id; + if(sc.hasNext()){ + h=sc.nextInt(); + if(sc.hasNext()){ + m=sc.nextInt(); + if(sc.hasNext()){ + id=sc.next(); + return new Time(h, m, id); + } + } + } + return null; + } + + public int toMinute(){ + if(id.equals("pm")) + h+=12; + return h*60+m; + } + + public boolean isAfter(Time t){ + return this.toMinute()12){ + this.id="pm"; + this.h-=12; + }else + this.id="am"; + } + + 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"; + } + + + private String id; + private int h; + private int m; +}