展开全部
static class CalculationResult {
//和
private double sum;
//差
private double discrepancy;
//积
private double product;
//商
private double quote;
public double getSum() {
return this.sum;
}
public void setSum(double sum) {
this.sum = sum;
}
public double getDiscrepancy() {
return this.discrepancy;
}
public void setDiscrepancy(double discrepancy) {
this.discrepancy = discrepancy;
}
public double getProduct() {
return this.product;
}
public void setProduct(double product) {
this.product = product;
}
public double getQuote() {
return this.quote;
}
public void setQuote(double quote) {
this.quote = quote;
}
@32313133353236313431303231363533e58685e5aeb931333337613931Override
public String toString() {
return "CalculationResult{" +
"sum=" + sum +
", discrepancy=" + discrepancy +
", product=" + product +
", quote=" + quote +
'}';
}
}
/**
* 使用对象返回
*
* @param numA
* @param numB
* @return
*/
private static CalculationResult calcTwoNum(double numA, double numB) {
CalculationResult result = new TestEntry.CalculationResult();
result.setSum(numA + numB);
result.setDiscrepancy(numA - numB);
result.setProduct(numA * numB);
result.setQuote(numA / numB);
return result;
}
/**
* 使用map返回
*
* @param numA
* @param numB
* @return
*/
public static Map calcTwoNumMap(double numA, double numB) {
Map mapRtn = new HashMap();
mapRtn.put("sum", numA + numB);
mapRtn.put("discrepancy", numA + numB);
mapRtn.put("product", numA * numB);
mapRtn.put("quote", numA / numB);
return mapRtn;
}
public static void main(String[] args){
//返回对象调用
System.out.println(calcTwoNum(1, 3));
//返回map调用
System.out.println(calcTwoNumMap(2, 8));
}