不会编译,主要方法缺失

时间:2013-07-14 14:12:06

标签: java

嗨大家好,并且下面的程序问题一直告诉我“公共类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

1 个答案:

答案 0 :(得分:7)

您似乎正在尝试运行没有CellularPhone方法的main()。您必须运行包含CellularPhoneDriver方法

main
>java CellularPhoneDriver