Я хочу получить два значения из функции в GUI, один из которых является double, а другой - типом int. в моем интерфейсе проверки чека я хочу иметь значение двух переменных, которые являются profitAmount и quantityItemSold, которые будут обновляться значениями, вычисленными в классе register.java, поскольку я выполнял java-объекты, передаются по ссылке, поэтому я создал объекты Double profitAmount и Integer quantityItemSold и передали их в функции 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});
}
//shop.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);
}
//register.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.