Natalia__krkrkr

Класс Комплексных чисел

Aug 23rd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. public class  ComplexNumber {
  2.     private int real ;
  3.     private int imaginary;
  4.  
  5.     public class  ComplexNumber {
  6.     private int real ;
  7.     private int imaginary;
  8.  
  9.     ComplexNumber(){
  10.         this.real  = this.imaginary = 0;
  11.     }
  12.     ComplexNumber(int real, int imaginary){
  13.         this.setReal(real);
  14.         this.setImaginary(imaginary);
  15.     }
  16.  
  17.     public void  setReal  (int real){
  18.         this.real = real; // прим. ты вызываешь этот же метод бесконечное количество раз
  19.     }
  20.  
  21.     public void setImaginary (int imaginary){
  22.         this.imaginary = imaginary; // прим. то же самое, что для setReal
  23.     }
  24.  
  25.     public int getReal  (){
  26.         return this.real ;
  27.     }
  28.  
  29.     public int getImaginary (){
  30.         return this.imaginary;
  31.     }
  32.  
  33.     public double module (int real, int imaginary){
  34.         double m = Math.sqrt(Math.pow(real,2)+Math.pow(imaginary,2));
  35.         return m;
  36.     }
  37.  
  38.     public ComplexNumber sum (ComplexNumber num){
  39.         return new ComplexNumber(this.real+num.real, this.imaginary+ num.imaginary);
  40.     }
  41.  
  42.     public ComplexNumber multiply (ComplexNumber num){
  43.         ComplexNumber number = new ComplexNumber(this.real*num.real-this.imaginary*num.imaginary,
  44.                 this.real*num.imaginary-this.imaginary*num.real);
  45.         return number;
  46.     }
  47.  
  48.     public ComplexNumber subtraction (ComplexNumber num){
  49.         return new ComplexNumber(this.real-num.real, this.imaginary-num.imaginary);
  50.     }
  51.  }
Advertisement
Add Comment
Please, Sign In to add comment