Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1.  
  2.     public void test() {
  3.         // Wykorzystanie konstruktorów:
  4.         Complex c1 = new Complex(2.5, 13.1);
  5.         Complex c2 = new Complex(-8.5, -0.9);
  6.         System.out.println(c1); // 2.5 + 13.1i
  7.         System.out.println(c2); // -8.5 - 0.9i
  8.         System.out.println(new Complex(4.5)); // 4.5
  9.         System.out.println(new Complex()); // 0.0
  10.         System.out.println(new Complex(0, 5.1)); // 5.1i
  11.         System.out.println();
  12.  
  13.         // Stałe typu Complex:
  14.         System.out.println(Complex.I); // 1.0i
  15.         System.out.println(Complex.ZERO); // 0.0
  16.         System.out.println(Complex.ONE); // 1.0
  17.         System.out.println();
  18.  
  19.         // Wykorzystanie metod zwracających wynik obliczeń:
  20.         System.out.println("Re(c1) = " + c1.getRe()); // Re(c1) = 2.5
  21.         System.out.println("Im(c1) = " + c1.getIm()); // Im(c1) = 13.1
  22.         System.out.println("c1 + c2 = " + Complex.add(c1, c2)); // c1 + c2 = -6.0 + 12.2i
  23.         System.out.println("c1 - c2 = " + Complex.subtract(c1, c2)); // c1 - c2 = 11.0 + 14.0i
  24.         System.out.println("c1 * c2 = " + Complex.multiply(c1, c2)); // c1 * c2 = -9.46 - 113.6i
  25.         System.out.println("c1 * 15.1 = " + Complex.multiply(c1, 15.1)); // c1 * 15.1 = 37.75 + 197.81i
  26.         System.out.println("c1 / c2 = " + Complex.divide(c1, c2)); // c1 / c2 = -0.4522310429783739 - 1.4932931836846426i
  27.         System.out.println("|c1| = " + c1.mod()); // |c1| = 13.336416310238668
  28.         System.out.println("sqrt(243.36) = " + Complex.sqrt(243.36)); // sqrt(243.36) = 15.6
  29.         System.out.println("sqrt(-243.36) = " + Complex.sqrt(-243.36)); // sqrt(-243.36) = 15.6i
  30.         Complex c3 = new Complex(2.5, 13.1);
  31.         System.out.println(c1.equals(c2)); // false
  32.         System.out.println(c1.equals(c3)); // true
  33.         // Poniższe wywołanie - dla chętnych :)
  34.         // System.out.println(c1.equals("test ze zlym obiektem")); // false
  35.         System.out.println();
  36.  
  37.         // Metoda zamieniająca liczbę na jej sprzężenie:
  38.         c1.conjugate();
  39.         System.out.println("c1* = " + c1); // c1* = 2.5 - 13.1i
  40.  
  41.         // Metoda zamieniająca liczbę na przeciwną:
  42.         c1.opposite();
  43.         System.out.println("-c1 = " + c1); // -c1 = -2.5 + 13.1i
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement