Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class ComplexNumberDriver {
- final static String TITLE = "Imaginary Numbers";
- public static void main(String[] args) {
- //String TITLE = "Imaginary Numbers";
- double real;
- double imag;
- String realString;
- String imagString;
- while (true) {
- realString = JOptionPane.showInputDialog(null, "Enter Real Value of First Complex Number", TITLE, 1);
- imagString = JOptionPane.showInputDialog(null, "Enter Imaginary Value of First Complex Number", TITLE, 1);
- real = Double.parseDouble(realString);
- imag = Double.parseDouble(imagString);
- Complex c1 = new Complex(real, imag);
- realString = JOptionPane.showInputDialog(null, "Enter Real Value of Second Complex Number", TITLE, 1);
- imagString = JOptionPane.showInputDialog(null, "Enter Imaginary Value of Second Complex Number", TITLE, 1);
- real = Double.parseDouble(realString);
- imag = Double.parseDouble(imagString);
- Complex c2 = new Complex(real, imag);
- Complex plus = c1.add(c2);
- Complex minus = c1.subtract(c2);
- Complex times = c1.multiply(c2);
- Complex quot = c1.divide(c2);
- String outPut = "c1 = " + c1 +
- "\nc2 = " + c2 +
- "\nc1 + c2 = " + plus +
- "\nc1 - c2 = " + minus +
- "\nc1 * c2 = " + times +
- "\nc1 / c2 = " + quot +
- "\n-c1 = " + c1.negate() +
- "\n-c2 = " + c2.negate() +
- "\nConj c1 = " + c1.conjugate() +
- "\nConj c2 = " + c2.conjugate() +
- "\n|c1| = " + c1.abs() +
- "\n|c2| = " + c2.abs() +
- "\nDist = " + c1.distance(c2) +
- "\n==? = " + c1.equals(c2) +
- "\n>? = " + c1.greaterThan(c2) +
- "\n<? = " + c1.lessThan(c2);
- JOptionPane.showMessageDialog(null, outPut, TITLE, 1);
- int confirm = JOptionPane.showConfirmDialog(null, "Do this again?", TITLE, 1);
- if (!(confirm == JOptionPane.OK_OPTION))
- break;
- }
- JOptionPane.showMessageDialog(null, "Thank you for using " + TITLE, TITLE, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement