Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. /* LiczbyZespolone.java - klasa liczb zespolonych */
  2. import java.util.*;
  3. import java.lang.String;
  4.  
  5. class Zespolone {
  6.     public static class LiczbyZespolone {
  7.         private double re; // część rzeczywista
  8.         private double im; // część urojona
  9.  
  10.         /* konstruktor */
  11.         public LiczbyZespolone(Scanner input) {
  12.             System.out.println("Podaj czesc rzeczywista: ");
  13.             this.re = input.nextDouble();
  14.             System.out.println("Podaj czesc urojona: ");
  15.             this.im = input.nextDouble();
  16.         }
  17.  
  18.         /* dodawanie */
  19.         public static void add(LiczbyZespolone c1, LiczbyZespolone c2) {
  20.             double repart = c1.re + c2.re;
  21.             double impart = c1.im + c2.im;
  22.             System.out.println("Suma liczb urojonych wynosi: " + +repart + " + " + impart + "i");
  23.         }
  24.  
  25.         /* odejmowanie */
  26.         public static void sub(LiczbyZespolone c1, LiczbyZespolone c2) {
  27.             double repart = c1.re - c2.re;
  28.             double impart = c1.im - c2.im;
  29.             System.out.println("Roznica liczb urojonych wynosi: " + repart + " + " + impart + "i");
  30.         }
  31.  
  32.         /* mnożenie */
  33.         public static void multiply(LiczbyZespolone c1, LiczbyZespolone c2) {
  34.             double repart = c1.re * c2.re - c1.im * c2.im;
  35.             double impart = c1.re * c2.im + c1.im * c2.re;
  36.             System.out.println("Iloczyn liczb urojonych wynosi: " + repart + " + " + impart + "i");
  37.         }
  38.  
  39.         public static double module(LiczbyZespolone c) {
  40.             return Math.sqrt(Math.pow(c.re, 2) + Math.pow(c.im, 2));
  41.         }
  42.  
  43.         public static double realPart(LiczbyZespolone c) {
  44.             return c.re;
  45.         }
  46.  
  47.         public static double imPart(LiczbyZespolone c) {
  48.             return c.im;
  49.         }
  50.     }
  51.         public static void main(String[] args) {
  52.             Scanner input = new Scanner(System.in);
  53.             LiczbyZespolone c = new LiczbyZespolone(input);
  54.             System.out.println("Wartosc bezwzgledna liczb urojonych wynosi: " + LiczbyZespolone.module(c));
  55.             System.out.println("Czesc rzeczywista liczby zespolonej wynosi: " + LiczbyZespolone.realPart(c));
  56.             System.out.println("Czesc urojona liczby zespolonej wynosi: " + LiczbyZespolone.imPart(c));
  57.         }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement