I want to receive two values from a function in GUI one of that is double and other is of type int. in my check profit interface i want to have value of two variables that is profitAmount and quantityItemSold to be updated by values calculated in class register.java as i was implementing java objects are pass by reference so i made objects of Double profitAmount and Integer quantityItemSold and passed them into function of gui by respective objects.
List of Classes
//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);
}