2013-07-14 43 views
-1

嗨,大家有和下面的程序問題,它不斷告訴我「公共類CellularPhone中未識別的主要方法」。任何幫助表示感謝。不會編譯,主要方法丟失

第1部分:CellularPhone

public class CellularPhone 
{ 

private String phoneBrand; // variable get phone brand 
private String cellularCarrier; // variable see cellular carrier 
private String phoneColor; // variable to get phone color 

// Accesor Method 
//method to return the Phone Brand 

public String getphoneBrand() 
{ 
return this.phoneBrand; 
} 

// method to return cellular carrier 
public String getCellularCarrier() 
{ 
return this.cellularCarrier; 
} 

//method to return phone color 
public String getPhoneColor() 
{ 
return this.phoneColor; 
} 
//******************************************************** 

//Mutator method 

//method to change phone brand 
public void setCellularBrand(String setCellularBrand) 
{ 
this.phoneBrand=setBrand; 
} 
//method to change cellular carrier 
public void setCellularCarrier(String setCellularCarrier) 
{ 
this.cellularCarrier=setCarrier; 
} 
//method to change phone color 
public void setPhoneColor(String setPhoneColor) 
{ 
this.phoneColor=setColor; 
} 
} // end CellularPhone 

第2 CellularPhoneDriver

import java.util.Scanner; 

public class CellularPhoneDriver 
{ 

    public static void main(String[] args) 
    { 
     Scanner std= new Scanner(System.in); 

     firstCellularPhone= new CellularPhone(); // Creation of first phone (instantiation) 
     secondCellularPhone= new CellularPhone(); // Creation of second phone (instantiation) 
     thirdCellularPhone= new CellularPhone(); // Creations of third phone (instantiation) 

     firstCellularPhone.setBrand("Apple"); // Setting brand for first phone 
     firstCellularPhone.setCarrier("AT&T"); // Setting cellular carrier for first phone 
     firstCellularPhone.setColor("white"); // Set color to phone first phone 

     secondCellularPhone.setBrand("Samsung"); // Setting brand for second phone 
     secondCellularPhone.setCarrier("Verizon"); // Setting cellular carrier for second phone 
     secondCellularPhone.setColor("blue"); // Set color to phone second phone 

     thirdCellularPhone.setBrand("Motorola"); // Setting brand for third phone 
     thirdCellularPhone.setCarrier("Sprint"); // Setting cellular carrier for third phone 
     thirdCellularPhone.setColor("black"); // Set color to phone third phone 


     System.out.println("The first phone is manufactured by "+firstCellularPhone.getPhoneBrand()+", licensed under "+firstCellularPhone.getCellularCarrier()+" and its color is "+firstCellularPhone.getPhoneColor()+"."); 
     System.out.println("The second phone is manufactured by "+secondCellularPhone.getPhoneBrand()+", licensed under "+secondCellularPhone.getCellularCarrier()+" and its color is "+secondCellularPhone.getPhoneColor()+"."); 
     System.out.println("The third phone is manufactured by "+thirdCellularPhone.getPhoneBrand()+", licensed under "+thirdCellularPhone.getCellularCarrier()+" and its color is "+thirdCellularPhone.getPhoneColor()+"."); 
     } // End class main 
} // end class CellularPhoneDriver 
+2

這是執行錯誤,而不是一個編譯錯誤。 – EJP

+0

這個源代碼文件的名稱是什麼? – DarenW

+0

您可以使用一個簡單的在線搜索解決您的問題。我相信這個問題需要關閉。 – sheidaei

回答

7

看起來你正在嘗試運行CellularPhone,不具有main()方法。你必須運行CellularPhoneDriver其中包含main方法

>java CellularPhoneDriver