forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInterface.java
More file actions
85 lines (71 loc) · 2.3 KB
/
UserInterface.java
File metadata and controls
85 lines (71 loc) · 2.3 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
package textvježba;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author Tomislav
*/
public class UserInterface {
Scanner input = new Scanner(System.in);
private Mjesec mjesec = new Mjesec();
private Dan dan;
List<String> sati = new ArrayList<>();
public UserInterface() {
}
void run() throws IOException {
System.out.println("Odaberi opciju:");
System.out.println(" 1. Unesi podatke za današnji datum");
System.out.println(" 2. Unesi podatke za neki drugi datum");
System.out.println(" 3. Isprintaj cijeli mjesec");
int odabir = input.nextInt();
switch(odabir){
case 1: unesiSate();
case 4: mjesec.napraviNovuListu();
}
}
void unesiSate() {
double pocetakRada;
double krajRada;
System.out.print("Unesi pocetak rada: ");
pocetakRada = input.nextDouble();
System.out.print("Unesi kraj rada: ");
krajRada = input.nextDouble();
dan = new Dan(mjesec.dajBrojDana(), pocetakRada, krajRada);
sati.set(mjesec.date.getDay(), "dfs");
try {
ucitajSate();
} catch (Exception e) {
}
try {
ispisiUText();
for(String str: sati){
System.out.println(str);
}
} catch (Exception e) {
}
}
void ucitajSate() throws FileNotFoundException {
Scanner scanner = new Scanner(new File(mjesec.getPath()));
while (scanner.hasNextLine()) {
sati.add(scanner.nextLine());
}
}
void ispisiUText() throws IOException {
FileWriter writer = new FileWriter(mjesec.getPath());
for (String str : sati) {
writer.write(str);
writer.write("\r\n");
}
writer.close();
}
//Napravi fajl sa rednim brojevima za dane za cijeli mjesec
void pripremiMjesec(){
sati = mjesec.novaListaSati();
mjesec.napraviNovuListu();
}
}