Repository navigation
Expand file tree
/
Copy pathEstadistica.java
More file actions
127 lines (112 loc) · 3.98 KB
/
Copy pathEstadistica.java
File metadata and controls
127 lines (112 loc) · 3.98 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
124
125
126
127
/*
* 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.
*/
/**
*
* @author manum_000
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
public class Estadistica {
//esta clase recibe la respuesta proporcionada por el ninyo/a y suma aciertos o fallos
private int iAciertosM; //mates
private int iFallosM;
private int iAciertosI; //ingles
private int iFallosI;
private int iAciertosC; //castellano
private int iFallosC;
static private String sFichero = "src/estadisticas";
public Estadistica() throws FileNotFoundException, IOException { //inicializamos variables
File archivo = new File(sFichero);
if (archivo.createNewFile()) {
iAciertosM = 0;
iFallosM = 0;
iAciertosI = 0;
iFallosI = 0;
iAciertosC = 0;
iFallosC = 0;
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(archivo));
os.write(iAciertosM + "\n" + iFallosM + "\n" + iAciertosI
+ "\n" + iFallosI + "\n" + iAciertosC + "\n" + iFallosC);
os.close();
} else {
FileReader read = new FileReader(sFichero);
BufferedReader lec = new BufferedReader(read);
String leyendo;
int[] params = new int[6];
for (int i = 0; (leyendo = lec.readLine()) != null; i++) {
params[i] = Integer.parseInt(leyendo);
}
iAciertosM = params[0];
iFallosM = params[1];
iAciertosI = params[2];
iFallosI = params[3];
iAciertosC = params[4];
iFallosC = params[5];
}
}
/**
* para sumar aciertos o fallos se especifica el nombre de la asignatura que
* sera uno de los siguientes: mates, ing o cast.
*
* @param sAsig String
*/
public void acierto(String sAsig) throws FileNotFoundException, IOException {
//sumamos 1 por cada acierto
//mates
if (sAsig.compareToIgnoreCase("mates") == 0) {
iAciertosM++;
} else if (sAsig.compareToIgnoreCase("ing") == 0) {
iAciertosI++;
} else if (sAsig.compareToIgnoreCase("cast") == 0) {
iAciertosC++;
}
FileOutputStream fos = new FileOutputStream(new File(sFichero));
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write(iAciertosM + "\n" + iFallosM + "\n" + iAciertosI
+ "\n" + iFallosI + "\n" + iAciertosC + "\n" + iFallosC);
osw.close();
}
public void fallo(String sAsig) throws IOException {
//sumamos 1 por cada fallo
//mates
if (sAsig.compareToIgnoreCase("mates") == 0) {
iFallosM++;
} else if (sAsig.compareToIgnoreCase("ing") == 0) {
iFallosI++;
} else if (sAsig.compareToIgnoreCase("cast") == 0) {
iFallosC++;
}
FileOutputStream fos = new FileOutputStream(new File(sFichero));
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write(iAciertosM + "\n" + iFallosM + "\n" + iAciertosI
+ "\n" + iFallosI + "\n" + iAciertosC + "\n" + iFallosC);
osw.close();
}
public int getiAciertosM() {
return iAciertosM;
}
public int getiFallosM() {
return iFallosM;
}
public int getiAciertosI() {
return iAciertosI;
}
public int getiFallosI() {
return iFallosI;
}
public int getiAciertosC() {
return iAciertosC;
}
public int getiFallosC() {
return iFallosC;
}
}