Advertisement
Guest User

complex numbers

a guest
Feb 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1.  
  2. import javax.swing.JOptionPane;
  3.  
  4. public class ComplexNumberDriver {
  5.     final static String TITLE = "Imaginary Numbers";
  6.     public static void main(String[] args) {
  7.         //String TITLE = "Imaginary Numbers";
  8.  
  9.         double real;
  10.         double imag;
  11.         String realString;
  12.         String imagString;
  13.  
  14.         while (true) {
  15.             realString = JOptionPane.showInputDialog(null, "Enter Real Value of First Complex Number", TITLE, 1);
  16.             imagString = JOptionPane.showInputDialog(null, "Enter Imaginary Value of First Complex Number", TITLE, 1);
  17.             real = Double.parseDouble(realString);
  18.             imag = Double.parseDouble(imagString);
  19.             Complex c1 = new Complex(real, imag);
  20.  
  21.             realString = JOptionPane.showInputDialog(null, "Enter Real Value of Second Complex Number", TITLE, 1);
  22.             imagString = JOptionPane.showInputDialog(null, "Enter Imaginary Value of Second Complex Number", TITLE, 1);
  23.             real = Double.parseDouble(realString);
  24.             imag = Double.parseDouble(imagString);
  25.             Complex c2 = new Complex(real, imag);
  26.  
  27.  
  28.             Complex plus = c1.add(c2);
  29.             Complex minus = c1.subtract(c2);
  30.             Complex times = c1.multiply(c2);
  31.             Complex quot = c1.divide(c2);
  32.  
  33.            
  34.             String outPut = "c1      = " + c1 +
  35.             "\nc2      = " + c2 +
  36.             "\nc1 + c2 = " + plus +
  37.             "\nc1 - c2 = " + minus +
  38.             "\nc1 * c2 = " + times +
  39.             "\nc1 / c2 = " + quot +
  40.             "\n-c1     = " + c1.negate() +
  41.             "\n-c2     = " + c2.negate() +
  42.             "\nConj c1 = " + c1.conjugate() +
  43.             "\nConj c2 = " + c2.conjugate() +
  44.             "\n|c1|    = " + c1.abs() +
  45.             "\n|c2|    = " + c2.abs() +
  46.             "\nDist    = " + c1.distance(c2) +
  47.             "\n==?     = " + c1.equals(c2) +
  48.             "\n>?      = " + c1.greaterThan(c2) +
  49.             "\n<?      = " + c1.lessThan(c2);
  50.             JOptionPane.showMessageDialog(null, outPut, TITLE, 1);
  51.            
  52.          
  53.             int confirm = JOptionPane.showConfirmDialog(null, "Do this again?", TITLE, 1);
  54.             if (!(confirm == JOptionPane.OK_OPTION))
  55.                 break;
  56.         }
  57.         JOptionPane.showMessageDialog(null, "Thank you for using " + TITLE, TITLE, 1);
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement