-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comparer.java
216 lines (182 loc) · 5.55 KB
/
Comparer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.io.File;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Comparer /*extends TimeKiller*/
{
static void printf(TimeKiller a)
{
System.out.printf("Timekiller date is %d/%d/%d/%d/%d",a.day,a.month,a.year,a.hour,a.minute);
}
static long TimeTransformer(TimeKiller a)
{
a.month=a.month-1;
String date = new String ();
date=date+a.day+"/"+a.month+"/"+a.year+"/"+a.hour+"/"+a.minute+"/"+a.second;
System.out.print("Timetransforming date \n");
System.out.print(date);
System.out.print("\n");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/mm/yyyy/HH/mm/ss");
try {
Date date1 = simpleDateFormat.parse(date);
System.out.println("Date is parsed");
return ((long)date1.getTime());//íåïðàâèëüíî ïàðñèò!!!!!!!!
} catch (java.text.ParseException e) {
System.out.println("Error parsing date");
return -1;
}
}
/*
public class MyClass
{
public void myMethod()
{
myNonStaticMethod();
}
public void myNonStaticMethod()
{
}
}
*/
public static long Compare(TimeKiller a) //âñòàâèòü àðãóìåíòû
{
int count=0;
Calendar calendar = Calendar.getInstance();
int day=calendar.get(calendar.DAY_OF_MONTH);
int month=calendar.get(calendar.MONTH)+1;
int year=calendar.get(calendar.YEAR);
int hour=calendar.get(calendar.HOUR_OF_DAY);
int minute=calendar.get(calendar.MINUTE);
int second=calendar.get(calendar.SECOND);
System.out.print("Setting TimeKiller as current date and time");
TimeKiller b=new TimeKiller(day,month,year,hour,minute,second);
//long begin= System.currentTimeMillis(); //ýòî ñêîëüêî ìèëëèñåêóíä ïðîøëî îò íà÷àëà 1970 ãîäà
System.out.print("System interpreted current TimeKiller date is \n");
printf(b);
System.out.print("\n");
System.out.print("System interpreted end TimeKiller date is \n");
printf(a);//here we find out that a is the same as b, why????????????
long end=TimeTransformer(a);
System.out.print("a is transformed \n");
long begin=TimeTransformer(b);
System.out.print("b is transformed \n");
Date begindate=new Date(begin);
//ïèøåì ñòàðóþ äàòó
System.out.print("\n");
System.out.print("System interpreted current date is \n");
System.out.print(begindate);
System.out.print("\n");
Date enddate=new Date(end);
System.out.print("System interpreted end date is \n");
System.out.print(enddate);
System.out.print("\n");
if(end<=begin)
{
System.out.println("Error: end date has already come ");
return -1;
}
long currenttime=0;
double percent=0;
String filename=new String ();
//ïèøåì ñòàðóþ äàòó
System.out.print("System interpreted current date is \n");
System.out.print(begindate);
System.out.print("System interpreted end date is \n");
System.out.print(enddate);
filename=filename+calendar.get(calendar.DAY_OF_MONTH)+"."+calendar.get(calendar.MONTH)+"."+calendar.get(calendar.YEAR)+"."+calendar.get(calendar.HOUR_OF_DAY)+"."+calendar.get(calendar.MINUTE)+"."+calendar.get(calendar.SECOND)+"-";
filename=filename+a.day+"."+a.month+"."+a.year+"."+a.hour+"."+a.minute+"."+a.second+".txt";//ýòî ìû çàïèñàëè ôèíàëüíóþ äàòó
System.out.print("Filename is ");
System.out.print(filename);
File file = new File(filename);//txt ôàéë èìÿ - íà÷ êîí âðåìÿ
try
{
if(!file.exists())
{
file.createNewFile();
System.out.print("File created");
}
}
catch(IOException e)
{
System.out.print("Exception occurred while creating file");
return -1;
}
try
{
PrintWriter out = new PrintWriter(file.getAbsoluteFile());
do
{
currenttime=System.currentTimeMillis();
percent= ((double)(end-currenttime)/(double)(end-begin));
out.printf("%f \n",percent);
//ïèøåì â ôàéë ðàññòîÿíèå â ïðîöåíòàõ
}
while(currenttime<end);
System.out.println("All is recorded");
out.close();
}
catch(FileNotFoundException e)
{
System.out.print("File not found");
return -1;
}
return 0;
}
public static void main(String[] args){
System.out.print("Input date in format DAY MONTH YEAR HOUR MINUTE");
Scanner in=new Scanner(System.in);
int count=0;
int day=0;
int month=0;
int year=0;
int second=0;
int minute=0;
int hour=0;
//do {
switch (count)
{
case 0:
System.out.print("Input day \n");
day=in.nextInt();
System.out.printf("Final day is %d \n", day);
count++;
case 1:
System.out.print("Input month \n");
month=in.nextInt();
System.out.printf("Final month is %d \n",month);
count++;
case 2:
System.out.print("Input year \n");
year=in.nextInt();
System.out.printf("Final year is %d \n",year);
count++;
case 3:
System.out.print("Input hour \n");
hour=in.nextInt();
System.out.printf("Final hour is %d \n",hour);
count++;
case 4:
System.out.print("Input minute \n");
minute=in.nextInt();
System.out.printf("Final minute is %d \n",minute);
count++;
case 5:
//second=in.nextInt();
second=0;
System.out.printf("Final second is %d \n",second);
count++;
in.close();
}
System.out.print("Setting TimeKiller with final date");
//if((0=<year<9999)&&(0<=month<13)&&(0<=day<32)&&(0<=hour<24)&&(0<=minute<60))
TimeKiller a = new TimeKiller(day,month,year,hour,minute,second);
//a.MaxLengthCheck(day,month,year,hour,minute,second);
Comparer.Compare(a);
in.close();
}
}