-
Notifications
You must be signed in to change notification settings - Fork 1
/
Granja.rb
100 lines (78 loc) · 2.88 KB
/
Granja.rb
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
=begin
LA GRANJA
En una granja se requiere saber alguna información para determinar el precio
de venta por cada kilo de huevo. Es importante determinar el promedio de calidad
de las n gallinas que hay en la granja. La calidad de cada gallina se obtiene según la formula:
calidad = peso de la gallina * altura de la gallina * numero de huevos que pone
Finalmente para fijar el precio del kilo de huevo, se toma como base la siguiente tabla:
RANGO DE CALIDAD PRECIO DE KILO DE HUEVO
mayor o igual que 15 1.20 * promedio de calidad
mayor que 8 y menor que 15 1.00 * promedio de calidad
menor o igual que 8 0.80 * promedio de calidad
Con los datos obtenidos se solicita lo siguiente:
1. Determinar cual es la calidad de una gallina.
2. Determinar cual es la calidad de una muestra.
3. Determinar cual es el precio del kilo de huevos de una muestra de gallinas.
=end
def calcularCalidadGallina(peso, altura, huevos)
total = peso * altura * huevos
return total.round(2)
end
def calcularCalidadGranja(pesos, alturas, huevos)
total = 0.0
cantidad_gallina = pesos
for i in 0...cantidad_gallina.size
total = total + (pesos[i] * alturas[i] * huevos[i])
end
return (total / cantidad_gallina.size).round(2)
end
def determinarPrecio(pesos, alturas, huevos)
calidad_granja = calcularCalidadGranja(pesos,alturas,huevos)
case calidad_granja
when 1..7.99
precio = calidad_granja * 0.80
when 8..14.99
precio = calidad_granja * 1.00
when 15..99.99
precio = calidad_granja * 1.20
end
return precio.round(2)
end
#----------Zona de Test------------------
def probarCalcularCalidadGallina
print validate(7.74, calcularCalidadGallina(8.6,0.45,2))
print validate(5.32, calcularCalidadGallina(7.6,0.35,2))
print validate(3.50, calcularCalidadGallina(9.2,0.38,1))
end
def probarCalcularCalidadGranja
print validate(9.01, calcularCalidadGranja(@peso1, @altura1, @huevo1))
print validate(10.29, calcularCalidadGranja(@peso2, @altura2, @huevo2))
print validate(4.99, calcularCalidadGranja(@peso3, @altura3, @huevo3))
end
def probarDeterminarPrecio
print validate(9.01, determinarPrecio(@peso1, @altura1, @huevo1))
print validate(10.29, determinarPrecio(@peso2, @altura2, @huevo2))
print validate(3.99, determinarPrecio(@peso3, @altura3, @huevo3))
end
#----------------zona de test-----------------
@peso1 =[8.60,7.22,6.63,9.54]
@peso2 =[7.50,6.99,8.88,9.54]
@peso3 =[9.88,9.45,6.77,7.21]
@altura1 =[0.45,0.46,0.47,0.43]
@altura2 =[0.55,0.56,0.57,0.53]
@altura3 =[0.35,0.36,0.37,0.33]
@huevo1 =[2,2,3,3]
@huevo2 =[1,3,3,2]
@huevo3 =[2,1,1,3]
def validate (expected, value)
expected == value ? "." : "F"
end
def test
puts "Test de prueba del programa"
puts "---------------------------"
probarCalcularCalidadGallina
probarCalcularCalidadGranja
probarDeterminarPrecio
puts " "
end
test