Java - Problema con la clase y al añadir otra clase dentro del tipo de AVLTree

 
Vista:
Imágen de perfil de Juan José
Val: 54
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problema con la clase y al añadir otra clase dentro del tipo de AVLTree

Publicado por Juan José (20 intervenciones) el 14/12/2020 10:52:05
La clase LaboratoryManagement como atributo tiene una serie de datos que estarán dentro de un BSTreeMap, el cuál tendrá String, representará el nombre de un laboratorio y un AVLTree que será una lista de los sujetos que están en cada laboratorio.
Este sería el código de un Test que llamará a la Clase LaboratoryManagement

Dejo aqui explicado que la clase Suject contiene el nombre de un sujeto, la prueba que se ha realizado y sus resultados.

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
@Test
	public void testLaboratoryManagement() {
		LaboratoryManagement gestion = new LaboratoryManagement();
 
		assertTrue(gestion.addLaboratory("LAB_ALMERIA"));
		assertTrue(gestion.addLaboratory("LAB_GRANADA"));
		assertTrue(gestion.addLaboratory("LAB_MURCIA"));
		assertFalse(gestion.addLaboratory("LAB_MURCIA"));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Oswald", "prueba01", 1.0, 2.0, 3.0));
		assertTrue(gestion.add("LAB_GRANADA", "Oswald", "prueba01", 4.0, 5.0, 6.0));
		assertTrue(gestion.add("LAB_MURCIA", "Oswald", "prueba02", 1., 2., 3.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Edward", "prueba01", 1., 2., 3.));
		assertTrue(gestion.add("LAB_GRANADA", "Edward", "prueba01", 4., 5., 6.));
		assertTrue(gestion.add("LAB_MURCIA", "Edward", "prueba02", 1., 2., 3.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Alfred", "prueba01", 1., 2., 3.));
		assertTrue(gestion.add("LAB_GRANADA", "Alfred", "prueba02", 1., 2., 3.));
		assertTrue(gestion.add("LAB_MURCIA", "Alfred", "prueba03", 1., 2., 3.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Bruce", "prueba01", 1., 2., 3.));
		assertTrue(gestion.add("LAB_GRANADA", "Bruce", "prueba02", 1., 2., 3.));
		assertTrue(gestion.add("LAB_MURCIA", "Bruce", "prueba02", 4., 5., 6.));
 
		assertTrue(gestion.add("LAB_MURCIA", "Paulina", "prueba01", 1., 2., 3.));
		assertTrue(gestion.add("LAB_GRANADA", "Paulina", "prueba01", 4., 5., 6.));
		assertTrue(gestion.add("LAB_ALMERIA", "Paulina", "prueba01", 7., 8., 9.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Oswald", "prueba01", 7.0, 8.0, 9.0));
		assertTrue(gestion.add("LAB_MURCIA", "Oswald", "prueba01", 10.0, 11.0, 12.0));
		assertTrue(gestion.add("LAB_GRANADA", "Oswald", "prueba02", 4., 5., 6.));
 
		assertTrue(gestion.add("LAB_GRANADA", "Edward", "prueba01", 7., 8., 9.));
		assertTrue(gestion.add("LAB_ALMERIA", "Edward", "prueba01", 10., 11., 12.));
		assertTrue(gestion.add("LAB_MURCIA", "Edward", "prueba02", 4., 5., 6.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Alfred", "prueba01", 4., 5., 6.));
		assertTrue(gestion.add("LAB_GRANADA", "Alfred", "prueba02", 4., 5., 6.));
		assertTrue(gestion.add("LAB_MURCIA", "Alfred", "prueba03", 4., 5., 6.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Bruce", "prueba01", 4., 5., 6.));
		assertTrue(gestion.add("LAB_GRANADA", "Bruce", "prueba02", 7., 8., 9.));
		assertTrue(gestion.add("LAB_MURCIA", "Bruce", "prueba02", 10., 11., 12.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Paulina", "prueba01", 10., 11., 12.));
		assertTrue(gestion.add("LAB_GRANADA", "Paulina", "prueba01", 13., 14., 15.));
		assertTrue(gestion.add("LAB_MURCIA", "Paulina", "prueba01", 16., 17., 18.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Oswald", "prueba01", 7.0, 8.0, 9.0));
		assertTrue(gestion.add("LAB_GRANADA", "Oswald", "prueba01", 10.0, 11.0, 12.0));
		assertTrue(gestion.add("LAB_MURCIA", "Oswald", "prueba02", 4., 5., 6.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Edward", "prueba01", 13., 14., 15.));
		assertTrue(gestion.add("LAB_GRANADA", "Edward", "prueba01", 16., 17., 18.));
		assertTrue(gestion.add("LAB_MURCIA", "Edward", "prueba02", 7., 8., 9.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Alfred", "prueba01", 7., 8., 9.));
		assertTrue(gestion.add("LAB_GRANADA", "Alfred", "prueba02", 7., 8., 9.));
		assertTrue(gestion.add("LAB_MURCIA", "Alfred", "prueba03", 7., 8., 9.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Bruce", "prueba01", 7., 8., 9.));
		assertTrue(gestion.add("LAB_GRANADA", "Bruce", "prueba02", 13., 14., 15.));
		assertTrue(gestion.add("LAB_MURCIA", "Bruce", "prueba02", 16., 17., 18.));
 
		assertTrue(gestion.add("LAB_ALMERIA", "Paulina", "prueba01", 19., 20., 21.));
		assertTrue(gestion.add("LAB_GRANADA", "Paulina", "prueba01", 22., 23., 24.));
		assertTrue(gestion.add("LAB_MURCIA", "Paulina", "prueba01", 25., 26., 27.));
 
		assertFalse(gestion.add("LAV_GRANADA", "Paulina", "prueba01", 28., 29., 30.));
 
		assertTrue(gestion.size() == 15);
 
		assertEquals(
				"[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]",
				gestion.getPuntuaciones("Alfred").toString());
 
		assertFalse(gestion.getPuntuaciones("Alfred", "prueba01").isEmpty());
		assertFalse(gestion.getPuntuaciones("Alfred", "prueba02").isEmpty());
		assertFalse(gestion.getPuntuaciones("Edward", "prueba02").isEmpty());
 
		assertTrue(gestion.getPuntuaciones("Edwardo", "prueba02").isEmpty());
		assertTrue(gestion.getPuntuaciones("Alfreda", "prueba02").isEmpty());
		assertTrue(gestion.getPuntuaciones("Edward", "prueba03").isEmpty());
 
		assertEquals(gestion.getPuntuaciones("Alfred", "prueba01"), gestion.getPuntuaciones("Alfred", "prueba02"));
		assertEquals(gestion.getPuntuaciones("Edward", "prueba02"), gestion.getPuntuaciones("Alfred", "prueba02"));
 
		assertEquals("[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]",
				gestion.getPuntuaciones("Edward", "prueba02").toString());
		assertEquals("[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]",
				gestion.getPuntuaciones("Bruce", "prueba01").toString());
 
		assertEquals(
				"[7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 19.0, 20.0, 21.0, 4.0, 5.0, 6.0, 13.0, 14.0, 15.0, 22.0, 23.0, 24.0, 1.0, 2.0, 3.0, 16.0, 17.0, 18.0, 25.0, 26.0, 27.0]",
				gestion.getPuntuaciones("Paulina").toString());
 
	}

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
package org.eda1.actividad03;
 
import java.util.ArrayList;
 
import org.eda1.edaAuxiliar.AVLTree;
 
public class LaboratoryManagement {
 
	BSTreeMap<String, AVLTree<Subject>> data = new BSTreeMap<String, AVLTree<Subject>>();
 
	public boolean addLaboratory(String laboratory) {
		//Si laboratorio existe, se devuelve false
		//En caso contrario insertamos el nuevo par en la estructura datos
		//...
		if(!data.containsKey(laboratory)) {
			data.put(laboratory, new BSTreeMap<String, AVLTree<Subject>>());
		}
	}
 
	public boolean add(String laboratory, String codeSubject, String testName, Double...punctuations) {
		//Si no existe el laboratorio, devuelve false;
		//En caso contrario se insertara el sujeto (que es posible que ya existe), el nombre del test y las puntuaciones obtenidas
		//...
	}
 
 
	public ArrayList<Double> getPuntuaciones(String codeSubject){
		ArrayList<Double> result = new ArrayList<Double>();
		Subject sujeto = new Subject(codeSubject);
		Subject current = null;
		//2 for()
		//...
		return result;
	}
 
	public ArrayList<Double> getPuntuaciones(String codeSubject, String testName){
		ArrayList<Double> result = new ArrayList<Double>();
		Subject sujeto = new Subject(codeSubject);
		Subject current = null;
		//2 for()
		//...
 
		return result;
	}
 
	public int size() {
		int size = 0;
		for (AVLTree<Subject> lab: data.values()) {
			size += lab.size();
		}
		return size;
	}
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Juan José
Val: 54
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problema con la clase y al añadir otra clase dentro del tipo de AVLTree

Publicado por Juan José (3 intervenciones) el 14/12/2020 13:53:49
Arreglado, a la Clase Subject se le añade esto:

1
2
3
4
5
6
7
8
9
public class Subject implements Iterable<Pair<String, ArrayList<Double>>>, Comparable<Subject >{
 
//El metodo de Override de Comparable:
	@Override
	public int compareTo(Subject o) {
		// TODO Auto-generated method stub
		return this.code.compareTo(o.code);
	}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de joel
Val: 194
Ha aumentado su posición en 4 puestos en Java (en relación al último mes)
Gráfica de Java

Problema con la clase y al añadir otra clase dentro del tipo de AVLTree

Publicado por joel (59 intervenciones) el 14/12/2020 19:50:07
Gracias por compartirlo!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar