1
我想从GUI中的函数接收两个值,其中一个是double,另一个是int类型。 在我的检查利润接口我想有两个变量的值是profitAmount和quantityItemSold由在类register.java中计算的值更新,因为我正在实现java对象是通过引用传递,所以我做了double profitAmount和Integer的对象quantityItemSold并通过各自的对象将它们传递给gui的函数。类的从java函数返回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概念违反刚刚保持类recieving只有两个变量。否则,该类保持空闲状态。 – 2014-11-22 07:41:23
你不能在java中做得更好。只要把它看作是元组的一个类比。 – dmitry 2014-11-22 07:43:03
@AbdullahJahangirAbbasi - 不,它不是。没有OOAD表示类需要复杂,用于很多事情等。 – 2014-11-22 12:35:30