gpt4 book ai didi

java - 短项目 : Electronics Inventory

转载 作者:太空宇宙 更新时间:2023-11-04 09:47:07 25 4
gpt4 key购买 nike

我正在做一个简短的项目,作为一种电子商店库存。以下是文本文件中的商品编号、描述、数量和价格列表:

65321,Tablet,54,150.00
91524,Monitors,24,125.50
25013,Printers,30,65.75
32841,Router,67,90.15
53214,Modem,50,50.50
26442,Hard Drive,14,40.89
30224,Power Supplies,44,125.44
41557,CPU,39,149.54
71561,Headphones,40,75.24

这是我到目前为止所做的:

库存计算.java

ArrayList<BookItem> inventory = new ArrayList<>();
BufferedReader inFile = new BufferedReader(new FileReader("C:\\Users\\Documents\\Data\\stock.txt"));
String line;
line = input.nextLine();
String[] tokens = line.split(",");
int itemNumber = Integer.parseInt(tokens[0]);
String description = tokens[1];
int quantity = Integer.parseInt(tokens[2]);
double unitCost = Double.parseDouble(tokens[3]);

System.out.println("Inventory Item");
System.out.println("Number Description Quantity Unit Price Value");

库存库存.java

public class InventoryItem {

private int itemNumber;
private String description;
private int quantity;
private double unitCost;

public InventoryItem(int itemNumber, String description, int quantity, double unitCost) {
this.itemNumber = itemNumber;
this.description = description;
this.quantity = quantity;
this.unitCost = unitCost;
}

public int getItemNumber() {
return itemNumber;
}

public void setItemNumber(int itemNumber) {
this.itemNumber = itemNumber;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public double getUnitCost() {
return unitCost;
}

public void setUnitCost(double unitCost) {
this.unitCost = unitCost;
} }

我无法弄清楚如何获得每件元素的总值(value)。我需要看到的结果如下

预期输出:

Number  Description           Quantity  Unit Price         Value
65321 Tablets 54 150.00 8,100.00
91524 Monitors 24 125.50 3,012.00
25013 Printers 30 65.75 1,972.50
32841 Routers 67 90.15 6,040.05
53214 Modems 50 50.50 2,525.00
26442 Hard Drives 14 40.89 572.46
30224 Power Supplies 44 125.44 5,519.36
41557 CPU 39 149.54 5,832.06
71561 Headphones 40 75.24 3,009.60

最佳答案

创建一个方法,将商品的总数量乘以单位成本,然后返回结果。将以下代码添加到您的 InventoryItem 类中。

 public double getTotalValueOfItem()
{
return unitCost * quantity;
}

关于java - 短项目 : Electronics Inventory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55288825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com