public class Goods {
private String numb;
private String name;
private double price;
//public String setNumb; 这三个是系统为了处理错误创建的,但是我不要public,而是private
//public String setName;
//public double setPrice;
public Goods(String numb,String name,double price){
super();
this.numb=numb;
this.name=name;
this.price=price;
}
public Goods(){
super();
}
public String getNumb(){
return numb;
}
public void setNumb(String numb){
this.numb=numb;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price=price;
}
@Override
public String toString(){
return this.numb+","+this.name+","+this.price;
}
}
以上是Goods类
import java.util.Scanner;
public class GoodsDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
Goods a=new Goods();
String numb=sc.next();
String name=sc.next();
double price=sc.nextDouble();
a.setNumb=(9967);//报错setNumb cannot be resolved or is not a field
a.setName=(name);//报错setName cannot be resolved or is not a field
a.setPrice=(price);//报错setPrice cannot be resolved or is not a field
a.toString();
//System.out.println(g);
}
}