1
7 public class AikaSekF implements AikaRajapinta {
8
9 private AikaF hm = new AikaF();
10 private int s;
11
12
18 public void aseta(int h,int m, int s) {
19 hm.aseta(h,m); this.s = s; lisaa(0,0);
20 }
21
22 public void aseta(int h,int m) { aseta(h,m,0); }
23 public void aseta(int h) { aseta(h,0); }
24
25 public AikaSekF() { aseta(0,0,0); }
26
27
33 public AikaSekF(int h,int m, int s) { aseta(h,m,s);
35 }
36
37 public AikaSekF(int h,int m) { aseta(h,m,0); }
38 public AikaSekF(int h) { aseta(h,0,0); }
39
40
44 public void tulosta(boolean lf) {
45 System.out.print(toString());
46 if ( lf ) System.out.println();
47 }
48
49
52 public void tulosta() {
53 tulosta(true);
54 }
55
56
61 public void lisaa(int lisa_min,int lisa_sek) {
62 s += lisa_sek;
63 hm.lisaa(lisa_min+s/60);
64 s %= 60;
65 }
66
67 public void lisaa(int lisa_min) { lisaa(lisa_min,0); }
68
69 public int getH() { return hm.getH(); }
70 public int getM() { return hm.getM(); }
71 public int getS() { return s; }
72
73 public String toString() {
74 return hm.toString() + ":" + (s<10?"0":"")+s;
75 }
76
77
84 public boolean equals(Object o) {
85 if ( !(o instanceof AikaSekF) ) return hm.equals(o);
86 AikaSekF a = (AikaSekF)o;
87 return hm.equals(o) && getS() == a.getS();
88 }
89
90 public Object clone() {
91 return new AikaSekF(getH(),getM(),getS());
92 }
93
94 public int hashCode() {
95 return super.hashCode() + getS();
96 }
97
98 public static void main(String[] args) throws CloneNotSupportedException {
99 AikaF a1 = new AikaF();
100 AikaF a2 = new AikaF(13);
101 AikaF a3 = new AikaF(14,175);
102
103 a1.tulosta(); a2.tulosta(); a3.tulosta();
104 a1.aseta(12,15); a2.aseta(16,-15);
105 a1.tulosta(); a2.tulosta();
106
107 AikaSekF a4 = new AikaSekF(14,55,45); a4.tulosta();
108 a4.lisaa(3,30); a4.tulosta();
109
110 AikaRajapinta ajat[] = new AikaRajapinta[8];
112 ajat[0] = a1; ajat[1] = a2; ajat[2] = a3; ajat[3] = a4;
113 ajat[4] = new AikaSekF(23,59,59);
114 ajat[5] = new AikaSekF(12,15,02);
115 ajat[6] = new AikaSekF(12,15,03);
116 ajat[7] = (AikaSekF)a4.clone();
117
118 System.out.println(ajat[0].equals(ajat[5]));
119 System.out.println(ajat[5].equals(ajat[0]));
120 System.out.println(ajat[0].equals(ajat[6]));
121 System.out.println(ajat[6].equals(ajat[0]));
122 System.out.println(ajat[5].equals(ajat[6]));
123
124 for (int i=0; i < ajat.length; i++ ) {
125 ajat[i].tulosta(false); System.out.print(" +" + i + " => ");
126 ajat[i].lisaa(i); ajat[i].tulosta();
127 }
128 System.out.println(ajat[4].toString());
129
130
131 }
132
133
134
135 }
136
137