Last active
November 9, 2022 18:11
-
-
Save gonzaleztroyano/dc61dbd57345109477a3107b315f280f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Alumno: Pablo Gonzalez Troyano | |
* Grado en Ciencia, Gestion e Ingenieria de Servicios (Semipresencial) | |
* | |
* ENUNCIADO DEL EJERCICIO | |
* | |
* Un agricultor se dedica a la cria de pollos en su finca. Compra 240 pollos, | |
* gallinas y gallos, aptos para reproducirse. Por la experiencia de mas de 20 annos | |
* sabe que cada mes nacen entre 2 y 50 pollos. Ademas, mueren ente 1 y 5 pollos. | |
* Cada mes el agricultor vende ente el 0% y el 10% de la poblacion total. | |
* | |
* Run online on codeboard: https://codeboard.io/projects/357337 | |
* | |
* VCS: https://gist.github.com/gonzaleztroyano/dc61dbd57345109477a3107b315f280f | |
* | |
*/ | |
import java.util.Scanner; | |
public class Main { | |
public static void muestra_resumen(int pi, int npm_min, int npm_max, int mpm_min, int mpm_max, double vpm_min, double vpm_max, int mas, boolean flag_debug){ | |
System.out.println("\n=====\nSe realizaran los calculos con las siguientes variables:"); | |
System.out.println(" Poblacion Inicial: " + pi ); | |
System.out.println(" Nacimientos por mes: " + npm_min + " - " + npm_max); | |
System.out.println(" Muertes por mes: " + mpm_min + " - " + mpm_min); | |
System.out.println(" Ventas por mes: " + vpm_min*100 + "% - " + vpm_max*100 + "%"); | |
System.out.println(" Meses a simular: " + mas ); | |
System.out.println(" Modo Debug: " + flag_debug + "\n =====\n"); | |
} | |
public static int calcula(int pi, int npm_min, int npm_max, int mpm_min, int mpm_max, double vpm_min, double vpm_max, int mas, boolean flag_debug){ | |
//System.out.println(pi); | |
for (int i = 1; i <= mas; i++){ | |
// Calcular nacimientos | |
int nacimientos_mes = (int) (Math.random() * (npm_max - npm_min)) + npm_min; | |
if (flag_debug) { | |
System.out.println("Nacimientos mes " + i + ": " + nacimientos_mes); | |
}; | |
// Calcular muertes | |
int muertes_mes = (int) (Math.random() * (mpm_max - mpm_min)) + mpm_min; | |
if (flag_debug) { | |
System.out.println("Muertes mes " + i + ": " + muertes_mes); | |
}; | |
pi = pi + nacimientos_mes - muertes_mes; | |
// Calcular ventas | |
double ventas_mes = (double) (Math.random() * (vpm_max - vpm_min)) + vpm_min; | |
if (flag_debug) { | |
System.out.println("Ventas mes " + i + ": " + ventas_mes + "% // " + pi * ventas_mes + " uds."); | |
System.out.println("Uds ANTES vs DESPUES ventas: " + pi + " // " + (int) (pi - (pi * ventas_mes))); | |
System.out.println("\n"); | |
}; | |
pi = (int) (pi - (pi * ventas_mes)); | |
}; | |
return pi; | |
}; | |
public static void main(String[] args) { | |
int pi = 240; // Poblacion Inicial | |
int npm_min = 2; // Nacimientos por Mes - MINIMO | |
int npm_max = 50; // Nacimientos por Mes - MAXIMO | |
int mpm_min = 1; // Muertes por Mes - MINIMO | |
int mpm_max = 5; // Muertes por Mes - MAXIMO | |
double vpm_min = 0; // Ventas por Mes - MINIMO | |
double vpm_max = 0.05; // Ventas por Mes - MAXIMO | |
int mas = 3; // Meses a Simular | |
boolean flag_debug = true; // Mostrar o no el detalle de los calculos | |
System.out.println("Te damos la bienvenida a este simulador \nCalcularemos la poblacion de pollos de una finca"); | |
muestra_resumen(pi, npm_min, npm_max, mpm_min, mpm_max, vpm_min, vpm_max, mas, flag_debug); | |
// Modificacion de valores | |
System.out.println("Desea variar los datos anteriormente mostrados? (s/N)"); | |
Scanner scanner = new Scanner(System.in); | |
String variar = scanner.nextLine(); | |
if (variar.equals("S") | variar.equals("s")) { | |
System.out.println("Introduzca, separados por espacios, los siguientes valores:\n Poblacion Inicial, \n Nacimientos por Mes - MINIMO, \n Nacimientos por Mes - MAXIMO, \n Muertes por Mes - MINIMO, \n Muertes por Mes - MAXIMO, \n Ventas por Mes - MINIMO, \n Ventas por Mes - MAXIMO, \n Meses a Simular, \n DEBUG "); | |
System.out.println("Ejemplo: " + pi + " " + npm_min + " " + npm_max + " " + mpm_min + " " + mpm_max + " " + vpm_min + " " + vpm_max + " " + mas + " " + flag_debug); | |
System.out.println("SU RESPUESTA: "); | |
Scanner datos_variar = new Scanner(System.in); | |
pi = datos_variar.nextInt(); | |
npm_min = datos_variar.nextInt(); | |
npm_max = datos_variar.nextInt(); | |
mpm_min = datos_variar.nextInt(); | |
mpm_max = datos_variar.nextInt(); | |
vpm_min = datos_variar.nextDouble(); | |
vpm_max = datos_variar.nextDouble(); | |
mas = datos_variar.nextInt(); | |
flag_debug = datos_variar.nextBoolean(); | |
System.out.println("GRACIAS!"); | |
muestra_resumen(pi, npm_min, npm_max, mpm_min, mpm_max, vpm_min, vpm_max, mas, flag_debug); | |
}; | |
int pf = calcula(pi, npm_min, npm_max, mpm_min, mpm_max, vpm_min, vpm_max, mas, flag_debug); | |
System.out.println("\n\n=======================================\nLa poblacion sera de: " + pf + " individuos\n=======================================\n"); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment