Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.0 KiB

  1. package com.ugsbo.complexnumcalc;
  2. public class ComplexNumber {
  3. private Double realPart;
  4. private Double imaginaryPart;
  5. /**
  6. * @param realPart The real part of the complex Number
  7. * @param imaginaryPart The imaginary part of the complex Number
  8. */
  9. public ComplexNumber(Double realPart, Double imaginaryPart) {
  10. this.realPart = realPart;
  11. this.imaginaryPart = imaginaryPart;
  12. }
  13. /**
  14. * @return the realPart
  15. */
  16. public Double getRealPart() {
  17. return realPart;
  18. }
  19. /**
  20. * @param realPart the realPart to set
  21. */
  22. public void setRealPart(Double realPart) {
  23. this.realPart = realPart;
  24. }
  25. /**
  26. * @return the imaginaryPart
  27. */
  28. public Double getImaginaryPart() {
  29. return imaginaryPart;
  30. }
  31. /**
  32. * @param imaginaryPart the imaginaryPart to set
  33. */
  34. public void setImaginaryPart(Double imaginaryPart) {
  35. this.imaginaryPart = imaginaryPart;
  36. }
  37. /**
  38. * Checks if the given complex Number is equal to this object.
  39. *
  40. * @param complexNumber The number wich gets compared with this Instance
  41. * @return True if the complex Numbers are Equal
  42. */
  43. public boolean equals(ComplexNumber complexNumber) {
  44. if (this.realPart.equals(complexNumber.realPart) && this.imaginaryPart.equals(complexNumber.imaginaryPart)) {
  45. return true;
  46. } else {
  47. return false;
  48. }
  49. }
  50. /**
  51. * Adds two complex Numbers together.
  52. *
  53. * @param addend The complex Number.
  54. * @return The result of adding the two complex Numbers together, as a conplex
  55. * Number.
  56. */
  57. public ComplexNumber add(ComplexNumber addend) {
  58. Double sumRealPart, sumImaginaryPart;
  59. sumRealPart = this.realPart + addend.realPart;
  60. sumImaginaryPart = this.imaginaryPart + addend.imaginaryPart;
  61. ComplexNumber sum = new ComplexNumber(sumRealPart, sumImaginaryPart);
  62. return sum;
  63. }
  64. }