Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MedidorDeHumedad {
- private int nivelDeHumedad;
- MedidorDeHumedad(int nivelDeHumedad){
- this.nivelDeHumedad = nivelDeHumedad;
- }
- public int getHumedad(){
- return this.nivelDeHumedad;
- }
- public void setHumedad(int nivelDeHumedad) {
- this.nivelDeHumedad = nivelDeHumedad;
- }
- }
- public class Terreno {
- private MedidorDeHumedad[][] medidores;
- public Terreno(int ancho, int largo, int nivelDeHumedad){
- if (ancho <= 0 || largo <= 0 || nivelDeHumedad < 0 || nivelDeHumedad > 100){
- throw new Error("No respeta las pre-condiciones.");
- }
- this.medidores = new MedidorDeHumedad[largo][ancho];
- for (int i = 0; i < this.medidores.length; i++){
- for (int j = 0; j < this.medidores[i].length; j++){
- this.medidores[i][j] = new MedidorDeHumedad(nivelDeHumedad);
- }
- }
- }
- public MedidorDeHumedad obtenerMedidor(int largo, int ancho){
- return this.medidores[largo][ancho];
- }
- public int calcularPromedio(){
- int humedadTotal = 0;
- int cantidadDeMedidores = 0;
- for (int i = 0; i < this.medidores.length; i++){
- for (int j = 0; j < this.medidores[i].length; j++){
- humedadTotal += this.obtenerMedidor(i,j).getHumedad();
- cantidadDeMedidores++;
- }
- }
- return (humedadTotal/cantidadDeMedidores);
- }
- public int buscarMaximo(){
- int valorMaximo = 0;
- for (int i = 0; i < this.medidores.length; i++){
- for (int j = 0; j < this.medidores[i].length; j++){
- if (this.obtenerMedidor(i,j).getHumedad() >= valorMaximo){
- valorMaximo = this.obtenerMedidor(i, j).getHumedad();
- }
- }
- }
- return valorMaximo;
- }
- public int buscarMinimo(){
- int valorMinimo = 0;
- for (int i = 0; i < this.medidores.length; i++){
- for (int j = 0; j < this.medidores[i].length; j++){
- if (this.obtenerMedidor(i,j).getHumedad() >= valorMinimo){
- valorMinimo = this.obtenerMedidor(i, j).getHumedad();
- }
- }
- }
- return valorMinimo;
- }
- public void modificarHumedad(int nivelDeHumedad, int ancho, int largo){
- this.obtenerMedidor(largo, ancho).setHumedad(nivelDeHumedad);
- }
- public int calcularContorno(int ancho, int largo){
- int humedadTotal = 0;
- humedadTotal = this.obtenerMedidor(largo + 1, ancho).getHumedad()
- + this.obtenerMedidor(largo, ancho + 1).getHumedad()
- + this.obtenerMedidor(largo - 1, ancho).getHumedad()
- + this.obtenerMedidor(largo, ancho - 1).getHumedad();
- return (humedadTotal/4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment