我想从 GUI 中的函数接收两个值,其中一个是双精度值,另一个是 int 类型。在我的检查利润界面中,我希望有两个变量的值,即利润金额和数量项目已售,以通过类寄存器中计算的值进行更新.java因为我正在实现 java 对象通过引用传递,所以我制作了双倍利润金额和整数数量项目已售的对象,并通过各自的对象将它们传递给 gui 函数。
类列表
//checkProfitOfItemInterface.java
if(checkButton==btnNewButtonCheck){
shop.checkProfit(jTextFieldItemCode.getText(),jTextFieldDate.getText(),profitAmount,quantityOfItemSold);
System.out.println("Quantity: "+ quantityOfItemSold + " Profit: "+ profitAmount);
//model.addRow(arg0);
model.addRow(new Object[]{"s","s",quantityOfItemSold,"s",profitAmount});
}
商店.java
public void checkProfit(String itemCode, String date, Double profitAmount, Integer quantityOfItemSold) {
int itemCodeInt = Integer.parseInt(itemCode);
ItemDescription objItemDescription =itemDescriptions.get(itemCodeInt);
register.checkProfit(itemCode,objItemDescription,date,profitAmount,quantityOfItemSold);
}
注册.java
public void checkProfit(String itemCode, ItemDescription itemDescription, String enteredDate,Double profitAmount, Integer quantityOfItemSold1) {
int itemCodeInt = Integer.parseInt(itemCode);
//GET no of sales being saved in register
int noOfSales = sales.size();
double salePrice=0;
double purchasePrice =0;
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date saleDate=null;
Date enteredDateToCheckProfitFrom = null;
int quantityOfItemSold =0;
for(int i=0;i<noOfSales;i++){
Sale objSale= sales.get(i);
//get date of required sale
saleDate = objSale.getDateOfSale();
try {
enteredDateToCheckProfitFrom = sdf.parse(enteredDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//compared entered date to required sale date
int value = enteredDateToCheckProfitFrom.compareTo(saleDate);
if(value >= 0){
quantityOfItemSold += objSale.getCountOfItemsInSale(itemCodeInt);
}
}
salePrice =itemDescription.getSalePrice();
purchasePrice = itemDescription.getPurchasePrice();
double profitOnSaleOfOneItem = salePrice - purchasePrice;
double totalProfit = quantityOfItemSold * profitOnSaleOfOneItem;
profitAmount = totalProfit;
quantityOfItemSold1 = quantityOfItemSold;
System.out.println("Quantity: "+ quantityOfItemSold1 + " Profit: "+ profitAmount);
}
听起来
你想使用一个 Pair 类来保存 Double 和 Integer 对象。
泛型对类