Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从java中的函数返回一个double和int值_Java - Fatal编程技术网

从java中的函数返回一个double和int值

从java中的函数返回一个double和int值,java,Java,我想从GUI中的函数接收两个值,一个是double,另一个是int类型。 在我的check profit接口中,我想让profitAmount和QuantityItemSell这两个变量的值通过类register.java中计算的值进行更新,因为我实现java对象是通过引用传递的,所以我创建了双profitAmount和整数QuantityItemSell的对象,并通过各自的方法将它们传递到gui函数中对象 课程表 //checkProfitOfItemInterface.java if(che

我想从GUI中的函数接收两个值,一个是double,另一个是int类型。 在我的check profit接口中,我想让profitAmount和QuantityItemSell这两个变量的值通过类register.java中计算的值进行更新,因为我实现java对象是通过引用传递的,所以我创建了双profitAmount和整数QuantityItemSell的对象,并通过各自的方法将它们传递到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);

}
public void checkProfit(String itemCode、itemsdescription itemsdescription、String enteredDate、Double profitAmount、Integer quantityOfItemSold1){
int itemCodeInt=Integer.parseInt(itemCode);
//获取保存在注册表中的销售数量
int noOfSales=sales.size();
双倍售价=0;
双重购买价格=0;
SimpleDataFormat sdf=新的SimpleDataFormat(“dd-MM-yyyy”);
日期saleDate=null;
输入日期到checkprofitfrom的日期=null;
int QuantityofItemSelled=0;
对于(int i=0;i=0){
QuantityOfItemsSaled+=objSale.getCountOfItemsInSale(itemCodeInt);
}
}
salePrice=itemDescription.getSalePrice();
purchasePrice=itemDescription.getPurchasePrice();
double profitOnSaleOfOneItem=销售价格-采购价格;
双倍利润总额=已售出项目的数量*其中一个项目的销售利润;
profitAmount=总利润;
quantityOfItemSold1=出售的项目数量;
系统输出打印项次(“数量:+quantityOfItemSold1+”利润:+profitAmount);
}

听起来好像您想使用Pair类来保存Double和Integer对象


它是否违反了OOAD的概念,就像保留一个只接收两个变量的类一样。否则,该类将保持空闲状态。在java中,您再也不能做得更好了。把它看作是一个元组的类似物。没有OOAD说类需要复杂,用于很多事情,等等。