iSay_namerace
Posted by donabel malagamba on Friday, July 8, 2011
Under: Copro2
import javax.swing.*;
class race implements Runnable{
String c;
class race implements Runnable{
String c;
race(String c) {
this.c = c;
}
this.c = c;
}
// override run() method in interface
public void run() {
for(int i=0; i<4999; i++) {
System.out.print(c);
try{
Thread.sleep((int)(Math.random()));
} catch( InterruptedException e ) {
System.out.println("Interrupted Exception caught");
}
}
System.out.println("is the winner");
}
public void run() {
for(int i=0; i<4999; i++) {
System.out.print(c);
try{
Thread.sleep((int)(Math.random()));
} catch( InterruptedException e ) {
System.out.println("Interrupted Exception caught");
}
}
System.out.println("is the winner");
}
public static void main(String[] args) {
String a = JOptionPane.showInputDialog("Enter the first competitor:");
String b = JOptionPane.showInputDialog("Enter the second competitor:");
String c = JOptionPane.showInputDialog("Enter the third competitor:");
race w= new race("\n"+a);
race j = new race("\n"+b);
race l = new race("\n"+c);
// start RunBasicThread objects as threadsrace j = new race("\n"+b);
race l = new race("\n"+c);
new Thread(w).start();
new Thread(j).start();
new Thread(l).start();
}
}
In : Copro2