Guest User

Untitled

a guest
Oct 1st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class Complex{
  2.  
  3. public double real,imaginar;
  4. public static int nrShow=0;
  5.  
  6. public Complex(double r ,double i ){
  7. this.real=r;
  8. this.imaginar=i;
  9. }
  10.  
  11.  
  12. public double modulComplex(){
  13. return Math.sqrt(this.real*this.real + this.imaginar*this.imaginar);
  14. }
  15.  
  16. public void showComplex(){
  17. System.out.println(this.real+"+i*"+this.imaginar);
  18. this.nrShow++;
  19. }
  20.  
  21.  
  22. public Complex getSum(Complex numar){
  23. double si=this.real+numar.real;
  24. double ri=this.imaginar+numar.imaginar;
  25. Complex resultSum=new Complex(si,ri);
  26.  
  27. return resultSum;
  28. }
  29.  
  30.  
  31. public static int getShow(){
  32. return nrShow;
  33. }
  34. }
  35.  
  36.  
  37. class ClientComplex{
  38.  
  39. public static void main(String[] args){
  40. Complex primNr=new Complex(3,4);
  41. System.out.print("Modul Numar Complex : ");
  42. System.out.println(primNr.modulComplex());
  43. primNr.showComplex();
  44.  
  45. System.out.print("Suma complex: ");
  46. Complex twoNr = new Complex(3,6);
  47. primNr.getSum(twoNr).showComplex();
  48.  
  49.  
  50. System.out.println("Afisari:"+ Complex.nrShow);
  51.  
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment