1
GUI의 함수에서 두 개의 값을 받고 싶습니다. 이중 하나는 double이고 다른 하나는 int 유형입니다. 내 체크 이익 인터페이스에서 나는 profitAmount 및 quantityItemSold 두 개의 변수의 값을 가지고 싶어 register.java 클래스에서 계산 된 값에 의해 업데이 트됩니다. 자바 객체를 구현할 때 참조로 전달되므로 Double profitAmount 및 Integer quantityItemSold 객체를 만들었습니다. 각각의 객체에 의해 gui의 기능으로 전달되었습니다. 클래스의자바의 함수에서 double 및 int 값을 반환합니다.
목록
//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);
}
는 두 변수를 잡위한 클래스를 유지하는 등 OOAD 개념을 위반하지 그것입니다. 그렇지 않으면 해당 클래스는 유휴 상태로 유지됩니다. –
자바에서 더 잘할 수 없습니다. 이것을 튜플의 아날로그로 생각하면됩니다. – dmitry
@AbdullahJahangirAbbasi - 아닙니다. 클래스가 복잡하고, 많은 것들을 위해 사용될 필요가 있다고 말하는 OOAD는 없습니다. –