This commit is contained in:
Orange_Dugongo 2016-10-19 18:43:43 +02:00
parent 2e0a9b667c
commit 5de9883c8c
4 changed files with 112 additions and 0 deletions

BIN
src/Time/Test.class Normal file

Binary file not shown.

16
src/Time/Test.java Normal file
View File

@ -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");
}
}

BIN
src/Time/Time.class Normal file

Binary file not shown.

96
src/Time/Time.java Normal file
View File

@ -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()<t.toMinute();
}
public boolean isBefore(Time t){
return !this.isAfter(t);
}
public void shift(int m){
int totm=this.toMinute() + m%(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";
}
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;
}