// Arup Guha
// 4/7/2026
// Driver Class to Test Complex Number Code.

import java.util.*;

public class TestComplexNumber {
	
	public static void main(String[] args) {
		
		// Give these initial values.
		double a1=0, b1=0, a2=0, b2=0;
		boolean done = false;
		
		// Read and validate input.
		while (!done) {
		
			// Try reading in the four values.
			try {
			
				/*** This work around works more easily than trying to clear the buffer. ***/
				// I am not sure if it's good style or not.
				Scanner stdin = new Scanner(System.in);
				
				// Get the first complex number.
				System.out.println("Enter a and b for your first complex number.");
				a1 = stdin.nextDouble();
				b1 = stdin.nextDouble();
		
				// And the second.
				System.out.println("Enter a and b for your second complex number.");
				a2 = stdin.nextDouble();
				b2 = stdin.nextDouble();
				
				// If we get here, we're good.
				done = true;
			}
			
			// Catch the format error.
			catch (InputMismatchException e) {
			
				// Print and clear the buffer.
				System.out.println("Sorry, you didn't enter a double for one of your entries.");
			}
		}
		
		// Create the two complex number objects.
		ComplexNumber n1 = new ComplexNumber(a1, b1);
		ComplexNumber n2 = new ComplexNumber(a2, b2);
		
		// These three should work.
		System.out.println(n1+" + "+n2+" = "+(n1.add(n2)));
		System.out.println(n1+" - "+n2+" = "+(n1.subtract(n2)));
		System.out.println(n1+" * "+n2+" = "+(n1.multiply(n2)));
		
		// Try the division.
		try {
			ComplexNumber div = n1.divide(n2);
			System.out.println(n1+" / "+n2+" = "+div);
		}
		
		// Didn't work. Just print out the issue.
		catch (DivideByZeroException e) {
			System.out.println("Sorry, you can not divide by 0.");
		}
	}
}