import java.util.Scanner;

/**
 * Prompts the user for two rational numbers and outputs the sum, difference, product,
 * quotient, and the sum of their squares.
 *
 * @author Drue Coles
 */
public class RationalCalculator {

    public static void main(String[] args) {

        System.out.print("Enter two rational numbers (without slashes): ");
        Scanner in = new Scanner(System.in);
        int n1 = in.nextInt();
        int d1 = in.nextInt();
        int n2 = in.nextInt();
        int d2 = in.nextInt();

        RationalNumber a = new RationalNumber(n1, d1);
        RationalNumber b = new RationalNumber(n2, d2);

        // Compute the sum, difference, and product.
        RationalNumber w = a.add(b);
        RationalNumber x = a.subtract(b);
        RationalNumber y = a.multiply(b);
        RationalNumber z = a.divide(b);

        System.out.printf("%s + %s = %s %n", a, b, w);
        System.out.printf("%s - %s = %s %n", a, b, x);
        System.out.printf("%s * %s = %s %n", a, b, y);
        System.out.printf("%s / %s = %s %n", a, b, z);

        // Compute the of the squares of a and b.
        RationalNumber sumOfSquares = a.multiply(a).add(b.multiply(b));
        System.out.printf("(%s)^2 + (%s)^2 = %s %n", a, b, sumOfSquares);
    }
}