-
9일 차 사용관계삼성SDS_멀티캠퍼스/Java 2015. 9. 17. 10:52반응형
class Complex {
private double real;
private double imag;
public double getReal() {
return real;
}
public void setReal(double real) {
this.real = real;
}
public double getImag() {
return imag;
}
public void setImag(double imag) {
this.imag = imag;
}
@Override
public String toString() {
return "Complex [real=" + real + ", imag=" + imag + "]";
}
public Complex() {
this.real = 4.0;
this.imag = 2.5;
}
public Complex(double r, double i) {
this.real = r;
this.imag = i;
}
public Complex add(Complex c) {
double resultReal = this.real + c.getReal();
double resultImag = this.imag + c.getImag();
return new Complex(resultReal, resultImag);
}
}
public class Test3 {public static void main(String[] args) {// TODO Auto-generated method stubComplex cp = new Complex(6.0, 3.5);Complex cp2 = new Complex(4.0, 2.3);Complex cp3 = new Complex();Complex cp4 = cp.add(cp2);Complex cp5 = cp4.add(cp3);System.out.println(cp);System.out.println(cp2);System.out.println(cp4);System.out.println(cp3);System.out.println(cp5);}}반응형'삼성SDS_멀티캠퍼스 > Java' 카테고리의 다른 글
9일 차 복소수의 분수계산 (0) 2015.09.17 9일 차 복소수에 관하여 (0) 2015.09.17 9일 차 생성자의 정적변수 접근 (0) 2015.09.17 9일 차 정적변수 (0) 2015.09.17 8일 차 시험(깊은 복사, 얕은 복사) (0) 2015.09.16