
public class CreateThread
{
  public static void main ( String [] args )
  {
    Score s = new Score();

   // s.setScore ( 1.0 );
    Athread t = new Athread( s );
    t.start();
    Athread1 t1 = new Athread1( s );
    t1.start();
    Athread0 t0 = new Athread0( s );
    t0.start();
//    Runnable runner = new Athread2 ();
//    Thread t2 = new Thread ( runner );
//    t2.start();

  }
}

class Athread extends Thread
{
    private Score score;

    //constructor
    public Athread ( Score s0 )
    {
	score = s0;
    }

    public void run()
    {
      System.out.println ("I am a thread!");
      
      for ( int i = 0; i < 10; i++ ) {
	System.out.println ( i + ":" + score.getScore () );
	try {
          Thread.sleep( (int) ( Math.random() * 1000 ) );
	} catch ( InterruptedException e ) {
	  e.printStackTrace();
        }
      }
    }
}


class Athread0 extends Thread
{
    private Score score;

    //constructor
    public Athread0 ( Score s0 )
    {
	score = s0;
    }

    public void run()
    {
      System.out.println ("I am a thread0!");
      
      for ( int i = 0; i < 10; i++ ) {
	System.out.println ( "Thread0: " + i  );
	score.updateScore ( i );
	try {
          Thread.sleep( (int) ( Math.random() * 1000 ) );
	} catch ( InterruptedException e ) {
	  e.printStackTrace();
        }
      }
    }
}

class Athread1 extends Thread
{
    private Score score;

    //constructor
    public Athread1 ( Score s0 )
    {
	score = s0;
    }

    public void run()
    {
      System.out.println ("I am a thread1!");
      double sum = 9.0;
 
      for ( int i = 0; i < 10; i++ ) {
	sum += i;
	score.setScore ( i );
	System.out.println ( "Thread1: " + i + ":" + score.getScore () );
	try {
          Thread.sleep( (int) ( Math.random() * 1000 ) );
	} catch ( InterruptedException e ) {
	  e.printStackTrace();
	}
      }
    }
}

class Athread2 implements Runnable
{
    public void run()
    {
	for ( int i = 0; i < 10; i++ ) {
          System.out.println ("I am a thread2!");
	  try {
            Thread.sleep( (int) ( Math.random() * 1000 ) );
	  } catch ( InterruptedException e ) {
	    e.printStackTrace();
	  }
        }
    }
}
