---
# System prepended metadata

title: 083 Calculator.java + TestCalculator.java

---

# 083 Calculator.java + TestCalculator.java
Calculator.java
package ch06;
/*
 * 建立方法並觀察參數傳遞與回傳值
 * 搭配TestCalculator.java一起使用
 */
public class Calculator {
	
	public int sum(int x, int y){
	     System.out.println("method-1");
	     return x + y;
	   }
	  
	  public float sum(float x, float y) {
	     System.out.println("method-2");
	     return x + y;
	  }
	  
	  public float sum(int x, float y) {
	    System.out.println("method-3");
	    return x + y;
	  }
	
}

TestCalculator.java
package ch06;
/*
 * 觀察方法傳入參數之間與回傳值的對應
 */
public class TestCalculator {

	public static void main(String[] args) {
		Calculator myCalculator = new Calculator();
	    
	    int sum1 = myCalculator.sum(1,2);
	    System.out.println(sum1);

//	    float sum2 = myCalculator.sum(3.0f, 4.0f);
//	    System.out.println(sum2);

//	    float sum3 = myCalculator.sum(5, 6.0f);
//	    System.out.println(sum3);

	}

}


