Advertisement
Guest User

#´poo3

a guest
Nov 28th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Thread;
  3.  
  4. public class Rollos {
  5.  
  6.     double alto;
  7.     double ancho;
  8.     double diametro;
  9.     boolean disponible = false;
  10.  
  11.    
  12.     public Rollos() {
  13.  
  14.     }
  15.  
  16.     public synchronized double send() {// envio
  17.         while (!disponible) {
  18.             try {
  19.                 wait();
  20.             } catch (Exception e) {
  21.                 System.out.println(e);
  22.             }
  23.         }
  24.  
  25.         disponible = true;//si le coloco false a este y true al delivery me tira la linea de sacado del rollo q habia metido antes no cacho q vola
  26.         notify();
  27.         return alto * ancho * diametro;
  28.         // return 2 + (3.14 * radio) * (alto + radio);
  29.  
  30.     }
  31.  
  32.     public synchronized void delivery(double alto, double ancho, double diametro) {// entrega
  33.         while (disponible) {
  34.             try {
  35.                 wait();
  36.             } catch (Exception e) {
  37.                 System.out.println(e);
  38.             }
  39.         }
  40.         this.alto = alto;
  41.         this.ancho = ancho;
  42.         this.diametro = diametro;
  43.         disponible = false;
  44.         notify();
  45.     }
  46.  
  47. }
  48.  
  49. class input extends Thread {// entrada
  50.     private Rollos rollo;
  51.  
  52.     public input(Rollos rollo) {
  53.         this.rollo = rollo;
  54.     }
  55.  
  56.     public void run() {
  57.         try {
  58.             System.out.println("Ingrese dimensiones del rollo: ");
  59.             Scanner sc = new Scanner(System.in);
  60.             String o = sc.nextLine();
  61.             String[] dato = o.split(",");
  62.  
  63.             rollo.delivery(Double.parseDouble(dato[0]),
  64.                     Double.parseDouble(dato[1]), Double.parseDouble(dato[2]));
  65.             System.out.println("Fue almacenado un rollo de dimensiones: "
  66.                     + Double.parseDouble(dato[0]) + " de Alto, "
  67.                     + Double.parseDouble(dato[1]) + " de Ancho y "
  68.                     + Double.parseDouble(dato[2]) + " de Diametro");
  69.             sc.close();
  70.  
  71.         } catch (Exception e) {
  72.  
  73.         }
  74.  
  75.     }
  76. }
  77.  
  78. class output extends Thread {// salida
  79.     private Rollos rollo;
  80.  
  81.     public output(Rollos rollo) {
  82.         this.rollo = rollo;
  83.     }
  84.  
  85.     public void run() {
  86.         double tamaño = rollo.send();
  87.         System.out.println("Fue retirado un rollo de tamaño " + tamaño + " cm3");
  88.     }
  89.  
  90. }
  91.  
  92. class Copy {
  93.     public static void main(String[] args) {
  94.  
  95.         Rollos r = new Rollos();
  96.         input i = new input(r);
  97.         output o = new output(r);
  98.         i.start();
  99.         o.start();
  100.  
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement