Java - Ayuda con este algoritmo en java

 
Vista:
Imágen de perfil de carlos

Ayuda con este algoritmo en java

Publicado por carlos (1 intervención) el 10/02/2016 17:53:36
Buenas

Necesito ayuda

como hago este algoritmo en java

- Escribir un algoritmo para calcular el promedio de una lista de notas de una cantidad N de alumnos (número de notas variable), y diga los aprobados, los desaprobados, la máxima nota y la mínima. La nota mínima para aprobar es 6

Gracias

Saludos
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

Ayuda con este algoritmo en java

Publicado por arck (145 intervenciones) el 11/02/2016 11:11:40
pregunta, cada alumno tiene una sola nota?
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
Imágen de perfil de Alejandro
Val: 23
Ha aumentado su posición en 2 puestos en Java (en relación al último mes)
Gráfica de Java

Ayuda con este algoritmo en java

Publicado por Alejandro (7 intervenciones) el 11/02/2016 22:36:12
Espero te sirva de algo este ejemplo, esta completo, lo deje corriendo es copiar pegar y probar resultados.
Saludos

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
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
 
public class PromedioNotas {
 
	public static void main(String[] args) {
 
		Map<Integer, Integer> notas = new HashMap<Integer, Integer>();
		for (int i = 1; i <= 20; i++) {
			Random r = new Random();
			notas.put(i, r.nextInt(i));
		}
 
		// calculando promedio de notas general
		Integer noteRange = getNoteRange(notas);
		printRangeMessage(noteRange);
 
		// calculando la nota para cada alumno
		Map<Integer, Integer> ap = getAproved(notas);
		Map<Integer, Integer> ad = getDesAproved(notas);
 
		// obteniendo los aprovados
		List<Integer> nMax = getListaOrdenada(ap.values().iterator());
		pintAprovedMessage(nMax);
 
		// obteniendo los desaprovados
		List<Integer> nMin = getListaOrdenada(ad.values().iterator());
		pintDesAprovedMessage(nMin);
 
		System.out.println("FIN");
 
	}
 
	private static void printRangeMessage(Integer noteRange) {
		String msg = String.format("Promedio de notas: %1$d", noteRange);
		System.out.println(msg);
		System.out.println();
	}
 
	private static void pintDesAprovedMessage(List<Integer> nMin) {
		String msg = String.format("Las notas aprovadas son %1$s",
				Arrays.asList(nMin));
		System.out.println(msg);
		msg = String.format("La mayor nota aprovada es %1$d",
				nMin.get(nMin.size() - 1));
		System.out.println(msg);
	}
 
	private static void pintAprovedMessage(List<Integer> nMax) {
		String msg = String.format("Las notas aprovadas son %1$s",
				Arrays.asList(nMax));
		System.out.println(msg);
		msg = String.format("La mayor nota aprovada es %1$d",
				nMax.get(nMax.size() - 1));
		System.out.println(msg);
	}
 
	private static Map<Integer, Integer> getAproved(Map<Integer, Integer> notas) {
		Map<Integer, Integer> ap = new HashMap<Integer, Integer>();
 
		for (int i = 1; i <= notas.size(); i++)
			if (notas.get(i) >= 6)
				ap.put(i, notas.get(i));
 
		return ap;
	}
 
	private static Map<Integer, Integer> getDesAproved(
			Map<Integer, Integer> notas) {
		Map<Integer, Integer> ad = new HashMap<Integer, Integer>();
 
		for (int i = 1; i <= notas.size(); i++)
			if (notas.get(i) < 6)
				ad.put(i, notas.get(i));
 
		return ad;
	}
 
	private static Integer getNoteRange(Map<Integer, Integer> notas) {
		Integer noteRange = 0;
		for (int i = 1; i <= notas.size(); i++)
			noteRange += notas.get(i);
 
		return noteRange / notas.size();
	}
 
	private static List<Integer> getListaOrdenada(Iterator<Integer> iterator) {
		List<Integer> nMax = new LinkedList<Integer>();
		while (iterator.hasNext()) {
			nMax.add(iterator.next());
		}
		Collections.sort(nMax);
		return nMax;
	}
}
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