- 分享
- 0
- 人气
- 0
- 主题
- 16
- 帖子
- 195
- UID
- 182764
- 积分
- 152
- 阅读权限
- 13
- 注册时间
- 2008-11-29
- 最后登录
- 2015-5-11
- 在线时间
- 615 小时
|
请帮帮忙,要交了还是有问题,谢谢。
不懂怎样加 Quantity
public class Item {
private int itemNumber;
private String itemDescription;
private double sellingPrice;
private static int quantityOnHand;
public Item() {
}
public Item(int in,String id,double sp){
itemNumber=in;
itemDescription=id;
sellingPrice=sp;
}
public int getItemNumber(){
return itemNumber;
}
public void setItemNumber(int sin){
itemNumber=sin;
}
public String getItemDescription(){
return itemDescription;
}
public void setItemDescription(String sid){
itemDescription=sid;
}
public double getSellingprice(){
return sellingPrice;
}
public void setSellingprice(double ssp){
sellingPrice=ssp;
}
public static int getQuantityOnHand(){
return quantityOnHand;
}
public static void setQuantityOnHand(int sqoh){
quantityOnHand = sqoh;
}
}
import java.util.Scanner;
public class testItem {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of book:");
int num = input.nextInt();
Item[] ItemArray = new Item[num];
for (int i = 0 ; i < ItemArray.length ; i++){
ItemArray = inputItemInfo();
}
System.out.println("code description price quantity");
System.out.println("=========================================");
for (int i = 0; i < ItemArray.length;i++){
System.out.printf("%d %s %.2f \n", ItemArray.getItemNumber(),ItemArray.getItemDescription(),ItemArray.getSellingprice());
}
}
public static Item inputItemInfo(){
Scanner input = new Scanner(System.in);
System.out.print("Enter the code :");
int itemNumber = input.nextInt();
System.out.print("Enter the description :");
String itemDescription = input.next();
System.out.print("Enter the selling price :");
float sellingPrice = input.nextFloat();
Item item = new Item(itemNumber,itemDescription,sellingPrice);
return item;
}
}
[ 本帖最后由 derrick90 于 2009-7-7 07:14 PM 编辑 ] |
|