From cb7b74f218aaee0b5e517ff23e3a9ed54bff8ba4 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Wed, 10 May 2006 23:26:37 +0000 Subject: [PATCH] Puntos 4.1 y 4.2 --- src/Cantadores.java | 22 ++++++++++++++++++++++ src/Sorteo.java | 28 ++++++++++++++++++++++++++++ src/Sorteo1.java | 13 +++++++++++++ src/Sorteo2.java | 17 +++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/Cantadores.java create mode 100644 src/Sorteo.java create mode 100644 src/Sorteo1.java create mode 100644 src/Sorteo2.java diff --git a/src/Cantadores.java b/src/Cantadores.java new file mode 100644 index 0000000..376d0e7 --- /dev/null +++ b/src/Cantadores.java @@ -0,0 +1,22 @@ +import java.util.*; + +public class Cantadores implements Observer +{ + String nombre; + public Cantadores (String s) + { + nombre = s; + } + + public void update(Observable obs, Object obj) + { + if (obs instanceof Sorteo) { + Sorteo s = (Sorteo)obs; + if ((s.getN()>=40) && (s.getN()<=49)) + System.out.println ("Canto "+nombre+" "+s.getN()); + } else { + System.out.println ("E"); + } + } +} + diff --git a/src/Sorteo.java b/src/Sorteo.java new file mode 100644 index 0000000..ccf3368 --- /dev/null +++ b/src/Sorteo.java @@ -0,0 +1,28 @@ + +import java.util.*; + +public class Sorteo extends Observable +{ + Random r = new Random (); + int n; + + public Sorteo () + { + } + + public int getN() + { + return n; + } + + public void Go () + { + while (true) { + /* Uso rango de 0 a 100 para que salga alguna vez :P */ + n = r.nextInt () % 100; + setChanged (); + notifyObservers (); + } + } +} + diff --git a/src/Sorteo1.java b/src/Sorteo1.java new file mode 100644 index 0000000..ea05612 --- /dev/null +++ b/src/Sorteo1.java @@ -0,0 +1,13 @@ + +public class Sorteo1 +{ + static public void main (String [] args) + { + Sorteo s = new Sorteo (); + Cantadores c = new Cantadores ("Pablo"); + s.addObserver (c); + + s.Go (); + } +} + diff --git a/src/Sorteo2.java b/src/Sorteo2.java new file mode 100644 index 0000000..1cc50c6 --- /dev/null +++ b/src/Sorteo2.java @@ -0,0 +1,17 @@ + +public class Sorteo2 +{ + static public void main (String [] args) + { + Sorteo s = new Sorteo (); + Cantadores c1 = new Cantadores ("Pablo"); + Cantadores c2 = new Cantadores ("Mariela"); + Cantadores c3 = new Cantadores ("Angela"); + s.addObserver (c1); + s.addObserver (c2); + s.addObserver (c3); + + s.Go (); + } +} + -- 2.43.0