// Time class, representing time as hours and minutes since midnight class Time { public static int timezone = 60; public final static Time noon = new Time(12, 0); private int hours, min; // since midnight public Time(int hours, int min) { this.hours = hours; this.min = min; } public Time(int hours) { this.hours = hours; } public Time(Time t) { hours = t.hours; min = t.min; } public int getHours() { return hours; } public int getMin() { return min; } public String toString() { return hours + "." + min + " (timezone: " + timezone + ")"; } public Time plus(int min) { int totalmin = 60 * this.hours + this.min + min; return new Time(totalmin / 60, totalmin % 60); } public int to(Time t) { return 60 * t.hours + t.min - 60 * hours - min; } public boolean before(Time t) { return hours < t.hours || hours == t.hours && min <= t.min; } public void flyt(int min) { int totalmin = 60 * this.hours + this.min + min; this.hours = totalmin / 60; this.min = totalmin % 60; } public void flyt(int hours, int min) { int totalmin = 60 * this.hours + this.min + 60 * hours + min; this.hours = totalmin / 60; this.min = totalmin % 60; } } // Test the Time class public class Time7 { public static void main(String[] args) { Time t1 = new Time(12, 35); Time t2 = new Time(t1); // t2 henviser til en kopi af t1 Time t3 = new Time(14); System.out.println("t1 er " + t1); t1.flyt(35); // Flytter t1 35 minutter System.out.println("t1 er nu flyttet 35 minutter " + t1); t1.flyt(1,30); // Flytter t1 1 time og 30 minutter System.out.println("t1 er nu flyttet 1 time og 30 minutter " + t1); System.out.println("t2 er " + t2); System.out.println("t3 er " + t3); } }