Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ComplexNumber {
- private int real ;
- private int imaginary;
- public class ComplexNumber {
- private int real ;
- private int imaginary;
- ComplexNumber(){
- this.real = this.imaginary = 0;
- }
- ComplexNumber(int real, int imaginary){
- this.setReal(real);
- this.setImaginary(imaginary);
- }
- public void setReal (int real){
- this.real = real; // прим. ты вызываешь этот же метод бесконечное количество раз
- }
- public void setImaginary (int imaginary){
- this.imaginary = imaginary; // прим. то же самое, что для setReal
- }
- public int getReal (){
- return this.real ;
- }
- public int getImaginary (){
- return this.imaginary;
- }
- public double module (int real, int imaginary){
- double m = Math.sqrt(Math.pow(real,2)+Math.pow(imaginary,2));
- return m;
- }
- public ComplexNumber sum (ComplexNumber num){
- return new ComplexNumber(this.real+num.real, this.imaginary+ num.imaginary);
- }
- public ComplexNumber multiply (ComplexNumber num){
- ComplexNumber number = new ComplexNumber(this.real*num.real-this.imaginary*num.imaginary,
- this.real*num.imaginary-this.imaginary*num.real);
- return number;
- }
- public ComplexNumber subtraction (ComplexNumber num){
- return new ComplexNumber(this.real-num.real, this.imaginary-num.imaginary);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment