2013-07-14 42 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