-
Lenguaje
Java usando Scanner
-
Descripción
Controle los datos generales de los pacientes de un hospital: Nombre, edad, sexo, estatura, peso y tipo de sangre. Y determine:
a) Número de hombres.
b) Hombres con tipo de sangre A.
c) Peso promedio de las mujeres.
d) Estatura promedio general.
e) Edad promedio general.
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
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
import java.util.Scanner;
public class DatosDePacientes {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, genero, pacientes, tipo_de_sangre;
double c, d, e, edad, estatura;
double peso;
String nombre;
String tecla_repetir;
a = 0;
b = 0;
pacientes = 0;
c = 0;
d = 0;
e = 0;
do {
System.out.print("Ingresa el nombre: ");
nombre = in.nextLine();
System.out.print("Ingresa el valor de edad: ");
edad = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de estatura: ");
estatura = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de peso: ");
peso = in.nextDouble();
in.nextLine();
in.nextLine();
System.out.println("Selecciona el valor de genero.");
System.out.println("\t1.- Mujer");
System.out.println("\t2.- Hombre");
System.out.print("\t: ");
do {
genero = in.nextInt();
in.nextLine();
if (genero<1||genero>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (genero<1||genero>2);
System.out.println("Selecciona el valor de tipo de sangre.");
System.out.println("\t1.- A");
System.out.println("\t2.- B");
System.out.println("\t3.- O");
System.out.println("\t4.- AB");
System.out.print("\t: ");
do {
tipo_de_sangre = in.nextInt();
in.nextLine();
if (tipo_de_sangre<1||tipo_de_sangre>4)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (tipo_de_sangre<1||tipo_de_sangre>4);
pacientes=pacientes+1;
d=d+estatura;
e=e+edad;
if(genero==2)
a=a+1;
if(genero==2&&tipo_de_sangre==1)
b=b+1;
if(genero==c)
c=c+peso;
System.out.println("Nombre: " + nombre);
System.out.println();
do {
System.out.print("\u00BFDeseas repetir el proceso? (S/N): ");
tecla_repetir = in.nextLine();
} while (!tecla_repetir.equalsIgnoreCase("s") && !tecla_repetir.equalsIgnoreCase("n"));
} while (tecla_repetir.equalsIgnoreCase("s"));
c=c/(pacientes-a);
if (pacientes == 0) {
d = 0;
} else {
d=d/pacientes;
}
if (pacientes == 0) {
e = 0;
} else {
e=e/pacientes;
}
System.out.println("Valor de a: " + a);
System.out.println("Valor de b: " + b);
System.out.println("Valor de pacientes: " + pacientes);
System.out.println("Valor de c: " + c);
System.out.println("Valor de d: " + d);
System.out.println("Valor de e: " + e);
}
}
public class DatosDePacientes {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, genero, pacientes, tipo_de_sangre;
double c, d, e, edad, estatura;
double peso;
String nombre;
String tecla_repetir;
a = 0;
b = 0;
pacientes = 0;
c = 0;
d = 0;
e = 0;
do {
System.out.print("Ingresa el nombre: ");
nombre = in.nextLine();
System.out.print("Ingresa el valor de edad: ");
edad = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de estatura: ");
estatura = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de peso: ");
peso = in.nextDouble();
in.nextLine();
in.nextLine();
System.out.println("Selecciona el valor de genero.");
System.out.println("\t1.- Mujer");
System.out.println("\t2.- Hombre");
System.out.print("\t: ");
do {
genero = in.nextInt();
in.nextLine();
if (genero<1||genero>2)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (genero<1||genero>2);
System.out.println("Selecciona el valor de tipo de sangre.");
System.out.println("\t1.- A");
System.out.println("\t2.- B");
System.out.println("\t3.- O");
System.out.println("\t4.- AB");
System.out.print("\t: ");
do {
tipo_de_sangre = in.nextInt();
in.nextLine();
if (tipo_de_sangre<1||tipo_de_sangre>4)
System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
} while (tipo_de_sangre<1||tipo_de_sangre>4);
pacientes=pacientes+1;
d=d+estatura;
e=e+edad;
if(genero==2)
a=a+1;
if(genero==2&&tipo_de_sangre==1)
b=b+1;
if(genero==c)
c=c+peso;
System.out.println("Nombre: " + nombre);
System.out.println();
do {
System.out.print("\u00BFDeseas repetir el proceso? (S/N): ");
tecla_repetir = in.nextLine();
} while (!tecla_repetir.equalsIgnoreCase("s") && !tecla_repetir.equalsIgnoreCase("n"));
} while (tecla_repetir.equalsIgnoreCase("s"));
c=c/(pacientes-a);
if (pacientes == 0) {
d = 0;
} else {
d=d/pacientes;
}
if (pacientes == 0) {
e = 0;
} else {
e=e/pacientes;
}
System.out.println("Valor de a: " + a);
System.out.println("Valor de b: " + b);
System.out.println("Valor de pacientes: " + pacientes);
System.out.println("Valor de c: " + c);
System.out.println("Valor de d: " + d);
System.out.println("Valor de e: " + e);
}
}