/*
* 본 코드는 생활코딩 Java 수업을 위해서 만들어진 코드입니다.
* http://o...content-available-to-author-only...s.org/module/516
* 누구든지 이 코드를 이용해서 원하는데로 사용할 수 있습니다. (public domain)
* 본 코드는 아래 수업에서 활용되고 있습니다.
* 실제 수업의 내용과 ideone.com의 코드는 다를 수 있습니다.
* ideone.com 플랫폼의 특성 때문입니다.
*/
import java.util.*;
import java.lang.*;
import java.io.*;
class Calculator2 {
static double PI = 3.14;
// 클래스 변수인 base가 추가되었다.
static int base = 0;
int left, right;
public void setOprands(int left, int right) {
this.left = left;
this.right = right;
}
public void sum() {
// 더하기에 base의 값을 포함시킨다.
System.
out.
println(this.
left + this.
right + base
); }
public void avg() {
// 평균치에 base의 값을 포함시킨다.
System.
out.
println((this.
left + this.
right + base
) / 2); }
}
class CalculatorDemo2 {
public static void main
(String[] args
) {
Calculator2 c1 = new Calculator2();
c1.setOprands(10, 20);
// 30 출력
c1.sum();
Calculator2 c2 = new Calculator2();
c2.setOprands(20, 40);
// 60 출력
c2.sum();
// 클래스 변수 base의 값을 10으로 지정했다.
Calculator2.base = 10;
// 40 출력
c1.sum();
// 70 출력
c2.sum();
}
}
LyoKKiDrs7gg7L2U65Oc64qUIOyDne2ZnOy9lOuUqSBKYXZhIOyImOyXheydhCDsnITtlbTshJwg66eM65Ok7Ja07KeEIOy9lOuTnOyeheuLiOuLpC4gCiogaHR0cDovL28uLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnMub3JnL21vZHVsZS81MTYKKiDriITqtazrk6Dsp4Ag7J20IOy9lOuTnOulvCDsnbTsmqntlbTshJwg7JuQ7ZWY64qU642w66GcIOyCrOyaqe2VoCDsiJgg7J6I7Iq164uI64ukLiAocHVibGljIGRvbWFpbikKKiDrs7gg7L2U65Oc64qUIOyVhOuemCDsiJjsl4Xsl5DshJwg7Zmc7Jqp65CY6rOgIOyeiOyKteuLiOuLpC4KKiDsi6TsoJwg7IiY7JeF7J2YIOuCtOyaqeqzv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