日期:2014-05-20 浏览次数:20702 次
class GoodsInfo { String name; float price; int num; float sum; public void setName(String name) { this.name = name; } public void setPrice(float price) { this.price = price; } public void setNum(int num){ this.num = num; } public String getName() { return name; } public float getPrice() { return price; } public int getNum() { return num; } public float getSum() { sum = price * num ; return sum; } } public class TestGoods { public static void main(String[] args) { GoodsInfo g = new GoodsInfo(); g.setName("沙发"); g.setPrice(800.0f); g.setNum(20); System.out.println("货品名称:" + g.getName()); System.out.println("货品单价:" + g.getPrice() + "元/套"); System.out.println("货品数量:" + g.getNum() + "元"); System.out.println("货品总价:" + g.getSum()+ "元"); } }