Laboratorio N°2: Nombre CI

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Nombre : Ancasi Fernando Jose CI : 7292079

LABORATORIO N°2
RMI_calculadora

Clase cliente.java

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this


license

* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template

*/

package RMI_Calculadora;

import javax.swing.JOptionPane;

import java.rmi.registry.Registry;

import java.rmi.registry.LocateRegistry;

import java.util.Scanner;

import java.rmi.Naming;

/**

* @author Once

*/

public class cliente {

public static void main(String [] args)

Scanner cs = new Scanner(System.in);

try{

Registry miRegistro = LocateRegistry.getRegistry( "localhost", 1099);

calculadora c = (calculadora)Naming.lookup("//localhost/calculadora");

while(true)

String menu = JOptionPane.showInputDialog("CALCULADORA RMI\n SELECCIONE


UNA DE LAS OPCIONES \n\n"

+"Ingrese (1)......SUMA\n"
+"Ingrese (2)......RESTA\n"

+"Ingrese (3)......MULTIPLICACION\n"

+"Ingrese (4)......DIVICION\n"

+"Ingrese (5)......POTENCIAS\n"

+"Ingrese (6)......MODULO\n"

+"Ingrese (7)......SENO\n"

+"Ingrese (8)......COSENO\n"

+"Ingrese (9)......RAIZ\n"

+"para terminar presione el boton CANCELARholamundo");

switch(menu)

case "1":

double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el primer


numero a sumar"));

double y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero a sumar"));

JOptionPane.showMessageDialog(null,"la suma es :"+ c.sum(x,y));

break;

case "2":

double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el primer


numero a restar"));

double y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero a restar"));

JOptionPane.showMessageDialog(null,"la resta es :"+ c.res(x,y));

break;
}

case "3":

double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el primer


numero a multiplicacion"));

double y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero a multiplicacion"));

JOptionPane.showMessageDialog(null,"la multiplicacion es :"+ c.mul(x,y));

break;

case "4":

double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el primer


numero a dividir"));

double y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero a dividir"));

JOptionPane.showMessageDialog(null,"la division es :"+ c.div(x,y));

break;

case "5":

double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la base"));

double y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
exponente"));

JOptionPane.showMessageDialog(null,"la potencia es :"+ c.pot(x,y));

break;

}
case "6":

double x = Integer.parseInt(JOptionPane.showInputDialog("El primer


numero"));

double y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese como lo


dividira"));

JOptionPane.showMessageDialog(null,"El modulo es :"+ c.mod(x,y));

break;

case "7":

double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
angulo"));

JOptionPane.showMessageDialog(null,"El seno del angulo es :"+ c.seno(x));

break;

case "8":

double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
angulo"));

JOptionPane.showMessageDialog(null,"El coseno del angulo es :"+ c.cos(x));

break;

case "9":

{
double x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la base"));

double y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la raiz"));

JOptionPane.showMessageDialog(null,"la raiz es :"+ c.raiz(x,y));

break;

}catch (Exception e){

System.out.println("Servidor no conectado "+ e);

Clase Mrmi.java

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this


license

* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template

*/

package RMI_Calculadora;

import java.rmi.server.UnicastRemoteObject;

import java.rmi.RemoteException;

/**

* @author Once

*/
public class Mrmi extends UnicastRemoteObject implements calculadora {

public Mrmi() throws RemoteException

double a,b;

@Override

public double sum(double a,double b) throws RemoteException

return a+b;

@Override

public double res(double a,double b) throws RemoteException

return a-b;

@Override

public double mul(double a,double b) throws RemoteException

return a*b;

@Override

public double div(double a,double b) throws RemoteException

return a/b;

@Override
public double pot(double a, double b) throws RemoteException

return Math.pow(a,b);

@Override

public double mod(double a, double b) throws RemoteException

return a%b;

@Override

public double seno(double a) throws RemoteException

return Math.sin(a);

@Override

public double cos(double a) throws RemoteException

return Math.cos(a);

@Override

public double raiz(double a, double b) throws RemoteException

return Math.pow(a,1/b);

}
Clase Servidor.java

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this


license

* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template

*/

package RMI_Calculadora;

import javax.swing.JOptionPane;

import java.rmi.registry.Registry;

/**

* @author Once

*/

public class servidor {

public static void main(String [] args)

try

Registry r = java.rmi.registry.LocateRegistry.createRegistry(1099);

r.rebind("calculadora",new Mrmi());

JOptionPane.showMessageDialog(null,"conectandose con el servidor");

}catch( Exception e){

JOptionPane.showMessageDialog(null,"No se pudo conectar con el servidor"+e);

}
calculadora.java

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this


license

* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this


template

*/

package RMI_Calculadora;

import java.rmi.Remote;

import java.rmi.RemoteException;

/**

* @author Once

*/

public interface calculadora extends Remote{

public double sum(double a, double b)throws RemoteException;

public double res(double a, double b)throws RemoteException;

public double mul(double a, double b)throws RemoteException;

public double div(double a, double b)throws RemoteException;

public double pot(double a, double b)throws RemoteException;

public double mod(double a, double b)throws RemoteException;

public double seno(double a)throws RemoteException;

public double cos(double a)throws RemoteException;

public double raiz(double a, double b)throws RemoteException;

You might also like