데블스캠프2009/수요일/JUnit/서민관 (rev. 1.1)
데블스캠프2009/수요일/JUnit/서민관 ¶
public class Calculator {
private int operand1;
private int operand2;
private char operator1;
private double result;
public double calculate(char op, int num1, int num2)
{
operand1 = num1;
operand2 = num2;
operator1 = op;
if (operator1 == '+')
{
addition();
}
else if (operator1 == '-')
{
subtraction();
}
else if (operator1 == '*')
{
multiplication();
}
else if (operator1 == '/')
{
division();
}
return result;
}
public void addition()
{
result = operand1 + operand2;
}
public void subtraction()
{
result = operand1 - operand2;
}
public void multiplication()
{
result = operand1 * operand2;
}
public void division()
{
result = operand1 / operand2;
}
}
Java로 만든 계산기에서 계산기 class 부분의 구현