2014-01-17 28 views
-4

我無法在Eclipse中運行此程序。 Eclipse沒有說任何錯誤,我只是無法打開它。每次嘗試時,它都會在我的默認包中打開另一個程序。我無法在Eclipse中運行此程序

import acm.util.*; 

/** 
* This class decides the face of a coin. 
* 1 and 2 represent correspondingly Heads and Tails. 
* Clients can get the "face" of the coin by calling getState() method. 
*/ 

public class CoinFace { 

    public CoinFace() { 
     state = rgen.nextInt(1, 2); 
    } 

    private int state; 

    public int getState() { 
     return state; 
    } 

    private RandomGenerator rgen = new RandomGenerator(); 
} 

public class ConsecutiveHeads extends CoinFace{ 
    public void run() { 
     while (true) { 
      int totalFlip = 0; 
      int consecutiveHeads = 0; 
      CoinFace a = new CoinFace(); 
      if (a.getState() == 1) { 
       System.out.print("Heads"); 
       totalFlip++; 
       consecutiveHeads++; 
      } else if (consecutiveHeads == 3) { 
       System.out.print("It took " + totalFlip + " to get 3 consecutive heads."); 
       break; 
      } else { 
       System.out.print("Tails"); 
       consecutiveHeads = 0; 
      } 
     } 
    } 
} 
+1

那麼當您嘗試會怎麼樣? CoinFace是什麼?你的'main'方法在哪裏?你沒有給我們足夠的信息。請閱讀http://tinyurl.com/so-list –

+0

我看不到這裏的主要方法 –

+2

我真的很希望你在那裏有'main' .. – Maroun

回答

4

你忘了聲明主要方法:

public static void main(String args[]) { 
    new ConsecutiveHeads().run(); 
}