forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMjesec.java
More file actions
123 lines (104 loc) · 3.42 KB
/
Mjesec.java
File metadata and controls
123 lines (104 loc) · 3.42 KB
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package textvježba;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
/**
*
* @author Tomislav
*/
public class Mjesec {
private String mjesec;
private int brojDanaUMjesecu;
private double ukupanBrojSati;
private double zaradeno;
private String path;
Calendar calendar;
Date date = new Date();
public Mjesec() {
calendar = new GregorianCalendar();
brojDanaUMjesecu = calendar.getActualMaximum(calendar.getTime().getMonth());
path = "F:" + File.separator + "Sati" + File.separator + dajMjesecUGodini() + ".txt";
}
public String dajMjesecUGodini() {
switch (calendar.getTime().getMonth()) {
case 0:
return "Siječanj";
case 1:
return "Veljača";
case 2:
return "Ožujak";
case 3:
return "travanj";
case 4:
return "Svibanj";
case 5:
return "Lipanj";
case 6:
return "Srpanj";
case 7:
return "Kolovoz";
case 8:
return "Rujan";
case 9:
return "Listopad";
case 10:
return "Studeni";
}
return "Prosinac";
}
void napraviNovuListu(){
File file = new File(path);
file.getParentFile().mkdirs();
try {
file.createNewFile();
FileWriter writer = new FileWriter(path);
for (String str : novaListaSati()) {
writer.write(str + ".");
writer.write("\r\n");
}
writer.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public String dajBrojDana(){
SimpleDateFormat dateFormat = new SimpleDateFormat("dd");
return "" + dateFormat.format(date);
}
//ispiši redne dane za cijeli mjesec
public List<String> novaListaSati(){
List<String> lista = new ArrayList<String>();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd");
calendar.setTime(date);
calendar.set(calendar.DAY_OF_MONTH, 1);
int myMonth = calendar.get(calendar.MONTH);
while (myMonth == calendar.get(calendar.MONTH)) {
lista.add(dateFormat.format(calendar.getTime()));
calendar.add(calendar.DAY_OF_MONTH, 1);
}
return lista;
}
void printDaysTEST(){
SimpleDateFormat dateFormat = new SimpleDateFormat("dd");
calendar.setTime(date);
calendar.set(calendar.DAY_OF_MONTH, 1);
int myMonth = calendar.get(calendar.MONTH);
while(myMonth == calendar.get(calendar.MONTH)){
System.out.println(dateFormat.format(calendar.getTime()));
calendar.add(calendar.DAY_OF_MONTH, 1);
}
}
public String getPath() {
return path;
}
}