Advertisement
Guest User

Untitled

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