public class Good
{
private String name;//商品名称;
private int price;//商品价格;
private int count;//商品数量
private int sumprice;//商品金额
public Good()
{
name="";
price=0;
count=0;
sumprice=0;
}
public Good(String name,int price,int count)
{
this.name=name;
this.price=price;
this.count=count;
}
public int getSumprice()
{
sumprice=price*count;
return sumprice;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) {
String name;
int price;
int count;
int sumprice;
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
System.out.println("请输入商品的名称:");
try {
String temp=input.readLine();
name=temp;
System.out.println("请输入商品的单价:");
temp=input.readLine();
price=Integer.parseInt(temp);
System.out.println("请输入商品的数量:");
temp=input.readLine();
count=Integer.parseInt(temp);
Good g=new Good(name,price,count);
System.out.println(name+"商品金额:"+g.getSumprice());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java代码,如有错漏,多提建议!
我用VS2010写的。
OK了,输入数据都检查了。