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