Advertisement
Guest User

Command Line Complex Number Driver

a guest
Feb 11th, 2017
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ComplexNumberDriver {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.  
  8.         double real;
  9.         double imag;
  10.  
  11.         while (true) {
  12.             System.out.print("Enter Real And Imaginary Components of Complex Number 1: ");
  13.             real = sc.nextDouble();
  14.             imag = sc.nextDouble();
  15.             Complex c1 = new Complex(real, imag);
  16.  
  17.             System.out.print("Enter Real And Imaginary Components of Complex Number 2: ");
  18.             real = sc.nextDouble();
  19.             imag = sc.nextDouble();
  20.             Complex c2 = new Complex(real, imag);
  21.            
  22.             sc.nextLine();
  23.  
  24.             Complex plus = c1.add(c2);
  25.             Complex minus = c1.subtract(c2);
  26.             Complex times = c1.multiply(c2);
  27.             Complex quot = c1.divide(c2);
  28.             System.out.println("c1      = " + c1);
  29.             System.out.println("c2      = " + c2);
  30.             System.out.println("c1 + c2 = " + plus);
  31.             System.out.println("c1 - c2 = " + minus);
  32.             System.out.println("c1 * c2 = " + times);
  33.             System.out.println("c1 / c2 = " + quot);
  34.             System.out.println("-c1     = " + c1.negate());
  35.             System.out.println("-c2     = " + c2.negate());
  36.             System.out.println("Conj c1 = " + c1.conjugate());
  37.             System.out.println("Conj c2 = " + c2.conjugate());
  38.             System.out.println("|c1|    = " + c1.abs());
  39.             System.out.println("|c2|    = " + c2.abs());
  40.             System.out.println("Dist    = " + c1.distance(c2));
  41.             System.out.println("==?     = " + c1.equals(c2));
  42.             System.out.println(">?      = " + c1.greaterThan(c2));
  43.             System.out.println("<?      = " + c1.lessThan(c2));
  44.            
  45.             System.out.print("Do again? ");
  46.             if (!sc.next().toUpperCase().equals("Y"))
  47.                 break;
  48.             sc.nextLine();
  49.         }
  50.  
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement