Advertisement
alduncin

Ventilador.java

Nov 19th, 2012
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | None | 0 0
  1. /**
  2. @author Karen Alduncin
  3.  */
  4. import java.util.*;
  5. import java.util.Random;
  6. import java.lang.Double;
  7. public class Ventilador
  8. {
  9.     private double temp;
  10.     private double tempinterior;
  11.     private int personas;
  12.     private String estado = "APAGADO";//"ENCENDIDO"
  13.     private String nivel = "NA";//"BAJO","MEDIO","ALTO","TURBO"
  14.     public static final double tempcorporal = 37.00;
  15.    
  16.     public Ventilador(double tp,double ti,int p)
  17.     {
  18.     temp =tp;
  19.     estado =(tp>26)?"ENCENDIDO":estado;
  20.     tempinterior =(ti==0.0)? tp + ((Ventilador.tempcorporal / tp ) * p):ti;
  21.     nivel="BAJO";
  22.     personas =p;
  23.     }
  24.     public Ventilador(double tp, int p)    
  25.     {
  26.     new Ventilador(tp,0.0,p);
  27.     }
  28.  
  29.  
  30.     public void cambiarexterior()
  31.     {
  32.     Random r = new Random();
  33.     double d = r.nextDouble();
  34.     if(temp<48)
  35.         temp = (d > 0.3)? temp +(10*r.nextDouble()): temp - (10*r.nextDouble());
  36.     else
  37.         temp = temp - (10*r.nextDouble());
  38.     }
  39.    
  40.     public void ajustar()
  41.     {
  42.     Random r = new Random();
  43.     double d = r.nextDouble();
  44.     estado =(temp>26)?"ENCENDIDO":"APAGADO";
  45.     //  System.out.println(toString());
  46.     if(temp>26&&temp<30||personas==1)
  47.         {
  48.         nivel="BAJO";
  49.         tempinterior=(r.nextDouble() *24 + 20);
  50.         }
  51.     else
  52.         {
  53.         if(temp>26&&temp<35||personas==2)
  54.             {
  55.             nivel="MEDIO";
  56.             tempinterior=19;
  57.             }
  58.         else
  59.             if(temp>26&&temp<40||personas==3)
  60.             {
  61.                 nivel="ALTO";
  62.                 tempinterior=18;
  63.             }
  64.         }
  65.     if(temp>40||personas>3)
  66.         {
  67.         nivel="TURBO";
  68.         tempinterior=(r.nextDouble() *17 + 15);
  69.         }    
  70.     }
  71.     public String toString()
  72.     {
  73.     return "\n" + estado + "\nNivel="+ nivel +"\nTemperatura EXTERIOR = " + temp + "\nPERSONAS = " + personas + "\nTemperatura INTERIOR = " + tempinterior;
  74.     }
  75.  
  76.     public static void main(String[] args)
  77.     {
  78.     Ventilador abanico = (args.length>2)? new Ventilador(Double.parseDouble(args[0]), Double.parseDouble(args[1]),Integer.parseInt(args[2])):
  79.                                           new Ventilador(Double.parseDouble(args[0]),Integer.parseInt(args[1]));
  80.  
  81.         System.out.println("ABANICO : "+abanico.toString());
  82.         if(Double.parseDouble(args[0])>26.0)
  83.            {
  84.  
  85.     for(int i=0;i<=3;i++){
  86.        
  87.         abanico.cambiarexterior();
  88.         abanico.ajustar();
  89.         System.out.println(abanico.toString());
  90.     }
  91.            }else
  92.             System.out.println("la temperatura es menor a 26 grados se mantendra el abanico en nivel bajo");
  93.     }
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement