-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLector.java
More file actions
97 lines (88 loc) · 3.24 KB
/
Copy pathLector.java
File metadata and controls
97 lines (88 loc) · 3.24 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
import java.util.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/*
* 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
*/
public class Lector {
FileReader read;
BufferedReader lec;
Nivel nTres;
Nivel nCinco;
Nivel nSiete;
public Lector() {
}
/**
* metodo que lee las preguntas del fichero txt de preguntas (separadas por ,#) y crea las clases correspondientes de nivel y pregunta
* @return array de objetos nivel (niveles 3,5,7) que contiene todos los datos que se han creado
* @throws FileNotFoundException
* @throws IOException
*/
public Nivel[] leerPreguntas() throws FileNotFoundException, IOException {
read = new FileReader("ruta de android");
lec = new BufferedReader(read);
String leyendo = null;
String splitter = ",#";
String[] params = null;//separa los parametros para el constructor de cada pregunta
String[] temp = null; //string en el que se pasarán las 4 opciones de respuesta
int lv; //nivel en el que se anyadira la pregunta
Nivel[] niveles;
niveles = new Nivel[3];
leyendo = lec.readLine();
while (leyendo != null) { //bucle que lee linea a linea hasta el final del fichero
params = leyendo.split(splitter);
temp = new String[4];
lv = Integer.parseInt(params[0]);
//asignamos las opciones en un array de strings auxiliar
temp[0] = params[5];
temp[1] = params[6];
temp[2] = params[7];
temp[3] = params[8];
//llamada constructor
Pregunta inPregunta;
inPregunta = new Pregunta(params[1], params[2], params[3], Integer.parseInt(params[4]), temp);
switch (lv) {
case 3:
nTres.anyadirPregunta(inPregunta);
break;
case 5:
nCinco.anyadirPregunta(inPregunta);
break;
case 7:
nSiete.anyadirPregunta(inPregunta);
break;
}
leyendo = lec.readLine();
}
niveles[0] = nTres;
niveles[1] = nCinco;
niveles[2] = nSiete;
return niveles;
}
/**
* metodo que lee el fichero que contiene en una linea el nombre de usuario y la contraseña separados por ',#'
* @return devuelve un array de string donde la pos 0 es el usuario y la pos 1 es la password
* @throws FileNotFoundException
* @throws IOException
*/
public String[] leerLogin() throws FileNotFoundException, IOException {
read = new FileReader("ruta de android");
lec = new BufferedReader(read);
String[] login = null;
String splitter = ",#";
String usuario=null;
String password=null;
String leyendo = null;
leyendo=lec.readLine();
login=leyendo.split(splitter);
return(login);
}
}