我是Java的初学者,我正在研究一个课程。我还发现Java很难掌握,并且我在此编译错误时遇到了麻烦。这只是一个错误,这使我更加困惑,因为当我在其他地方使用变量时我没有得到一个错误。
*错误 *
文件:d: programming project 2 product.java [line:47]
错误:NewComptype无法解析为变量
public class Product
{
//Instance variables
private String name; //Name of Product
private String compType; //Type of Product
private double price; //Price of Product
private int quantity; //How many computers
//Constructors
public Product()
{
name = "Dell";
compType = "Laptop";
price = 200;
quantity = 1;
}
public Product(String newName, String newCompType, double newPrice, int newQuantity)
{
name = newName;
compType = newCompType;
price = newPrice;
quantity = newQuantity;
}
//Instance methods
public void printData()
{
System.out.println("Name of computer: " + name);
System.out.println("Type of computer: " + compType);
System.out.println("Number of computers: " + quantity);
System.out.println("Cost of computer: " + price);
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void setCompType(String setCompType)
{
compType = newCompType;
}
public String getCompType()
{
return compType;
}
public void setPrice(double newPrice)
{
price = newPrice;
}
public double getPrice()
{
return price;
}
public void setQuantity(int newQuantity)
{
quantity = newQuantity;
}
public int getQuantity()
{
return quantity;
}
public String toString(){
return name + " " + compType + " " + quantity + " " + price + "n";
}
}
in:
public void setCompType(String setCompType) {
compType = newCompType; // <-- should be setCompType instead of newCompType
}