Advertisement
Flaron

Udemy_34. ComplexOperations

Sep 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public class ComplexNumber {
  2. private double real;
  3. private double imaginary;
  4.  
  5. public ComplexNumber(double real, double imaginary) {
  6. this.real = real;
  7. this.imaginary = imaginary;
  8. }
  9.  
  10. public double getReal() {
  11. return real;
  12. }
  13.  
  14. public double getImaginary() {
  15. return imaginary;
  16. }
  17.  
  18. public void add(double real, double imaginary){
  19. this.real += real;
  20. this.imaginary += imaginary;
  21. }
  22.  
  23. public void subtract(double real, double imaginary){
  24. this.real -= real;
  25. this.imaginary -= imaginary;
  26. }
  27.  
  28. public void add(ComplexNumber otherComplex){
  29. add(otherComplex.getReal(), otherComplex.getImaginary());
  30. }
  31.  
  32. public void subtract(ComplexNumber otherComplex){
  33. subtract(otherComplex.getReal(), otherComplex.getImaginary());
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement