Bootstrap

java定义商品类,封装成员变量,输出对象pta


import java.util.Scanner;

class Goods{
	private String id;
	private String name;
	private double price;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	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;
	}
	
	public Goods(String id,String name,double price) {
		this.id=id;
		this.name=name;
		this.price=price;
	}
	@Override
	public String toString() {
		return id+","+name+","+price;
	
	
	
}
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner (System.in);
		String id=sc.next();
		String name=sc.next();
		double price=sc.nextDouble();
		
		Goods g=new Goods(id,name,price);
		
		g.toString();
	}
 }

}

;