Advertisement
Edy_3112

Bebe

May 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. package babycare;
  2.  
  3. import java.util.*;
  4.  
  5. public class Bebe extends Thread {
  6.  
  7. private int matricula=0;
  8. private String nombre="";
  9. private String sexo="";
  10.  
  11. public Bebe() {
  12. }
  13.  
  14. public Bebe(int matricula){
  15. this.matricula=matricula;
  16. this.nombre="";
  17. this.sexo="";
  18. }
  19.  
  20. public Bebe(int matricula, String nombre, String sexo) {
  21. this.matricula = matricula;
  22. this.nombre = nombre;
  23. this.sexo = sexo;
  24. }
  25.  
  26.  
  27. @Override
  28. public void run(){
  29. this.aleatoriaactividad();
  30. }
  31.  
  32. public void dormir(){
  33. System.out.println("Bebe "+this.matricula+" esta durmiendo");
  34. try{
  35. Thread.sleep(5000);
  36. }
  37. catch (InterruptedException e ) {
  38. Thread.currentThread().interrupt();
  39. }
  40. System.out.println("Bebe "+this.matricula+" ya no esta durmiendo");
  41. }
  42.  
  43. public void comer(){
  44. System.out.println("Bebe "+this.matricula+" esta Comiendo");
  45. try{
  46. Thread.sleep(3500);
  47. }
  48. catch (InterruptedException e ) {
  49. Thread.currentThread().interrupt();
  50. }
  51. System.out.println("Bebe "+this.matricula+" dejo de Comer");
  52. }
  53.  
  54. public void cambiarpanal(){
  55. System.out.println("Bebe "+this.matricula+" estan cambiandole pañal");
  56. try{
  57. Thread.sleep(2000);
  58. }
  59. catch (InterruptedException e ) {
  60. Thread.currentThread().interrupt();
  61. }
  62. System.out.println("Bebe "+this.matricula+" tienen uevo pañal");
  63. }
  64.  
  65. public int aleatoriaactividad (){
  66. int i = (int) (Math.random() * 3) + 1;
  67. haceractividad(i);
  68. return i;
  69.  
  70. }
  71.  
  72. public void haceractividad(int i){
  73.  
  74. if (i==1){
  75. dormir();
  76. }
  77. else{
  78. if (i==2){
  79. comer();
  80. }
  81. else{
  82. if(i==3){
  83. cambiarpanal();
  84. }
  85. }
  86. }
  87.  
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement