이것은 CSE 숙제입니다. 친절한 사람들과 개랄한 사람들이 있을지도 모른다고 기대 했었습니다. 빨리 살펴보고 들어가면 좋을지 모릅니다. .CSE 214, Java, 복소수 도움말
(1) 어떤 매개 변수를 사용하지 않는 생성자 (여기서 기본값 : 여기
는가 함께 ComplexNumber 객체 클래스를 작성
안보국의 지시와 내가 쓴 코드입니다 이 경우 복소수의 0과 0i가되어야합니다.)
(2) 정수 유형의 실수와 허수 부분을 매개 변수로 취하는 다른 생성자
(3) 또 다른 복소수 c2를 매개 변수로 취하고 이것을 현재 복소수 에 추가하고 결과 복소수를 반환합니다. (4) 다른 복소수 c2를 매개 변수로 취하고 현재 복소수 this에서 c2를 뺀 다음 결과 복소수를 반환하는 빼기 방법.
(5) 다른 복소수 c2를 매개 변수로 사용하고 현재 복소수 this와 c2를 곱하는 곱셈 방식으로 결과 복소수를 반환합니다.
(6) 또 다른 복소수 c2를 매개 변수로 사용하여 현재 복소수를 c2로 나눈 결과 복소수를 반환하는 나누기 메소드.
(7) a + b의 형식으로 현재 복소수 인 문자열을 인쇄하는 toString1 메서드입니다. 여기서 a와 b는 자연수의 실수와 허수의 값이됩니다.
/*
* Kyle Arthur Benzle
* CSE 214
* 10/13/9
* Tagore
*
* This program takes two int variables and performs
* four mathematical operations (+, -, *, /) to them before returning the result from a toString1 method.
*/
//our first class Complex#
public class ComplexNumber {
// two int variables real and imagine
int real;
int imagine;
// Constructor, no parameters, setting our complex number equal to o + oi
ComplexNumber() {
real = 0;
imagine = 0; }
// Constructor taking two int variables as parameters.
ComplexNumber(int rePart, int imaginePart) {
real = rePart;
imagine = imaginePart; }
// This is the add method, taking object c2 as parameter, and adding it to .this to return
public ComplexNumber add(ComplexNumber c2) {
return new ComplexNumber(this.real + c2.real, this.imagine + c2.imagine); }
// Now the subtract method, followed by the methods to multiply and divide according to hand-out rules.
public ComplexNumber substract(ComplexNumber c2) {
return new ComplexNumber(this.real - c2.real, this.imagine - c2.imagine); }
public ComplexNumber multiply(ComplexNumber c2) {
ComplexNumber c3 = new ComplexNumber();
c3.real = this.real * c2.real - this.imagine * c2.imagine;
c3.imagine = this.real * c2.imagine + this.imagine * c2.real;
return c3; }
public ComplexNumber divide(ComplexNumber c2) {
ComplexNumber c3 = new ComplexNumber();
c3.real = this.real/c2.real - this.imagine/c2.imagine;
c3.imagine = this.real/c2.imagine + this.imagine/c2.real;
return c3; }
// toString1 method to return "a+bi" as a String.
public String toString1() {
return this.real + " + " + this.imagine + "i";
}
/* And we are all done, except for this last little } right here. */ }
유사한 질문이 이미 여기에서 닫았습니다. http://stackoverflow.com/questions/1562286/beginner-java-working-with-complex-numberbers 코드에 대한 질문이 있으면 질문하십시오. – Kevin