-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlashCardController.java
More file actions
executable file
·96 lines (84 loc) · 2.47 KB
/
Copy pathFlashCardController.java
File metadata and controls
executable file
·96 lines (84 loc) · 2.47 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
/*
Controller of the application
@author: Jesus Cuenca
*/
import java.util.*;
public class FlashCardController{
// Set up according to your database
// !!!! Get database parameters from an environment file
static String db="aleman";
static String user="changeme";
static String password="changeme";
private static void show(Flashcard fc){
System.out.println("German: "+ fc.aleman + ". Word type: " + fc.tipo_palabra + ". Image: " + fc.imagen + ". Cardholder: " + fc.cajon.toString());
}
private static boolean evaluate(Flashcard fc){
boolean res=true;
System.out.print("Introduce the traslation: ");
String respuesta=readLn();
if(fc.espanyol.equals(respuesta)){
System.out.println("Correct");
res= res && true;
}else{
System.out.println("Wrong. Answer: " + fc.espanyol);
res= res && false;
}
if(fc.declinaciones != null){
for(int i=1; i<=2; i++){
Random rg=new Random();
int indice= rg.nextInt(fc.declinaciones.size());
Vector declinacion=(Vector) fc.declinaciones.elementAt(indice);
System.out.print("What is the ");
for(int j=0; j< declinacion.size() -1; j++){
System.out.print(declinacion.elementAt(j) + " ");
}
System.out.print("? ");
respuesta=readLn();
if(declinacion.elementAt(declinacion.size()-1).toString().equals(respuesta)){
System.out.println("Correct");
res= res && true;
}else{
System.out.println("Wrong. Answer: " + declinacion.elementAt(declinacion.size()-1));
res= res && false;
}
}
}
return (res);
}
private static String readLn() {
byte [] byteArray = new byte[300];
try {
System.in.read(byteArray);
} catch (Exception ex) {
ex.printStackTrace();
}
String result = new String(byteArray);
int newLineIndex = result.indexOf("\n");
if (newLineIndex > -1)
result = result.substring(0,newLineIndex);
newLineIndex = result.indexOf("\r");
if (newLineIndex>-1)
result = result.substring(0,newLineIndex);
return result;
}
public static void main(String[] argv){
Flashcard fc;
DataBaseConnectionMgr.setConnectionParameters("org.postgresql.Driver",db,user,password);
FCDriver fcd=null;
try{
fcd=DataBaseConnectionMgr.getFCDriver();
}catch (Exception ex){
System.err.println("Error getting the flashcard driver");
ex.printStackTrace();
}
while(true){
fc=fcd.getFlashCard();
show(fc);
if(evaluate(fc)){
fcd.moveToNextBox(fc);
}else{
fcd.moveToFirstBox(fc);
}
}
}
}