-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavegar.java
More file actions
125 lines (94 loc) · 2.61 KB
/
Navegar.java
File metadata and controls
125 lines (94 loc) · 2.61 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
package robot.robonce;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import lejos.nxt.LightSensor;
/*
* Clase: Navegar
* Descripción: Realiza la navegación
* Autor: Miguel Ruiz Nogués.
*/
public class Navegar {
//Atributos:
Voicemanager vm;
LightSensor light;
Producto productos [];
//Lectura por Teclado:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String linea;
//Constructores:
public Navegar (LightSensor light, Producto productos [], Voicemanager vm){
this.light=light;
this.productos=productos;
this.vm=vm;
}
//Métodos:
/*
* Identificat Posición.
*
* Devuelve la posición del vector de productos donde se encuentra el robot, o -1 si no la conoce.
*/
public int identificar_posicion (){
int posicion=-1;
for (int i=0;i<4;i++)
{
if(productos[i].get_Color()==light.readValue())
{
posicion=i;
}
}
return posicion;
}
public void generar_trayectoria (){
}
/*
* DESTINO
*
* Devuelve el elemento al que se desea ir.
*/
public int destino (){
int opc=0;
do{
/*
System.out.println("Escoga el producto.");
System.out.println("1.Pan");
System.out.println("2.Leche");
System.out.println("3.Cereales");
System.out.println("4.Mermelada");
*/
vm.say("Choose a product");
vm.say("ham");
vm.say("cheese");
vm.say("orange");
vm.say("rise");
vm.say("Good Bye");
String opcion= vm.listen();
//System.out.println("He escuchado: "+opcion);
System.out.println("Leyendo: "+opcion);
int i=0;
boolean sw=false;
for(i=0;i<4;i++)
{
if(productos[i].get_Nombre().equals(opcion))
{
sw=true;
opc=i;
}
}
if(sw==false)
{
vm.say("Product not found.");
opc=-1;
}
//GOODBYE.
/*
try{
opc = Integer.parseInt(br.readLine())-1;
}
catch(Exception e){
e.printStackTrace();
}
*/
}while(opc<0 || opc>3);
return opc;
}
}