import org.acplt.oncrpc.*;
import java.io.IOException;
import java.net.InetAddress;
import java.util.Scanner;

public class CalculClientMain {
    public static void main(String[] args) throws Exception {
        InetAddress addr = InetAddress.getByName("localhost");
        CalculClient client = new CalculClient(addr, OncRpcProtocols.ONCRPC_TCP);

        Scanner sc = new Scanner(System.in);
        System.out.println("Client de calcul connecté au serveur.");

        while (true) {
            System.out.println("\nChoisissez le type d'opération :");
            System.out.println("1 - Addition int");
            System.out.println("2 - Soustraction int");
            System.out.println("3 - Multiplication int");
            System.out.println("4 - Division int");
            System.out.println("5 - Modulo int");
            System.out.println("6 - Addition float");
            System.out.println("7 - Soustraction float");
            System.out.println("8 - Multiplication float");
            System.out.println("9 - Division float");
            System.out.println("0 - Quitter");
            System.out.print("> ");
            int choix = sc.nextInt();

            if (choix == 0) break;

            switch (choix) {
                case 1: // Addition int
                    System.out.print("a = "); int a1 = sc.nextInt();
                    System.out.print("b = "); int b1 = sc.nextInt();
                    System.out.println("Résultat : " + client.add_1(a1, b1));
                    break;
                case 2: // Soustraction int
                    System.out.print("a = "); int a2 = sc.nextInt();
                    System.out.print("b = "); int b2 = sc.nextInt();
                    System.out.println("Résultat : " + client.sub_1(a2, b2));
                    break;
                case 3: // Multiplication int
                    System.out.print("a = "); int a3 = sc.nextInt();
                    System.out.print("b = "); int b3 = sc.nextInt();
                    System.out.println("Résultat : " + client.mul_1(a3, b3));
                    break;
                case 4: // Division int
                    System.out.print("a = "); int a4 = sc.nextInt();
                    System.out.print("b = "); int b4 = sc.nextInt();
                    System.out.println("Résultat : " + client.div_1(a4, b4));
                    break;
                case 5: // Modulo int
                    System.out.print("a = "); int a5 = sc.nextInt();
                    System.out.print("b = "); int b5 = sc.nextInt();
                    System.out.println("Résultat : " + client.mod_1(a5, b5));
                    break;
                case 6: // Addition float
                    System.out.print("a = "); float fa1 = sc.nextFloat();
                    System.out.print("b = "); float fb1 = sc.nextFloat();
                    System.out.println("Résultat : " + client.add_2(fa1, fb1));
                    break;
                case 7: // Soustraction float
                    System.out.print("a = "); float fa2 = sc.nextFloat();
                    System.out.print("b = "); float fb2 = sc.nextFloat();
                    System.out.println("Résultat : " + client.sub_2(fa2, fb2));
                    break;
                case 8: // Multiplication float
                    System.out.print("a = "); float fa3 = sc.nextFloat();
                    System.out.print("b = "); float fb3 = sc.nextFloat();
                    System.out.println("Résultat : " + client.mul_2(fa3, fb3));
                    break;
                case 9: // Division float
                    System.out.print("a = "); float fa4 = sc.nextFloat();
                    System.out.print("b = "); float fb4 = sc.nextFloat();
                    System.out.println("Résultat : " + client.div_2(fa4, fb4));
                    break;
                default:
                    System.out.println("Choix invalide.");
            }
        }
        System.out.println("Fin du client.");
    }
}