Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Thread;
- public class Rollos {
- double alto;
- double ancho;
- double diametro;
- boolean disponible = false;
- public Rollos() {
- }
- public synchronized double send() {// envio
- while (!disponible) {
- try {
- wait();
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- 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
- notify();
- return alto * ancho * diametro;
- // return 2 + (3.14 * radio) * (alto + radio);
- }
- public synchronized void delivery(double alto, double ancho, double diametro) {// entrega
- while (disponible) {
- try {
- wait();
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- this.alto = alto;
- this.ancho = ancho;
- this.diametro = diametro;
- disponible = false;
- notify();
- }
- }
- class input extends Thread {// entrada
- private Rollos rollo;
- public input(Rollos rollo) {
- this.rollo = rollo;
- }
- public void run() {
- try {
- System.out.println("Ingrese dimensiones del rollo: ");
- Scanner sc = new Scanner(System.in);
- String o = sc.nextLine();
- String[] dato = o.split(",");
- rollo.delivery(Double.parseDouble(dato[0]),
- Double.parseDouble(dato[1]), Double.parseDouble(dato[2]));
- System.out.println("Fue almacenado un rollo de dimensiones: "
- + Double.parseDouble(dato[0]) + " de Alto, "
- + Double.parseDouble(dato[1]) + " de Ancho y "
- + Double.parseDouble(dato[2]) + " de Diametro");
- sc.close();
- } catch (Exception e) {
- }
- }
- }
- class output extends Thread {// salida
- private Rollos rollo;
- public output(Rollos rollo) {
- this.rollo = rollo;
- }
- public void run() {
- double tamaño = rollo.send();
- System.out.println("Fue retirado un rollo de tamaño " + tamaño + " cm3");
- }
- }
- class Copy {
- public static void main(String[] args) {
- Rollos r = new Rollos();
- input i = new input(r);
- output o = new output(r);
- i.start();
- o.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement