Sei sulla pagina 1di 11

CALCULADORA REMOTA

MATERIA

ARQUITECTURA DE DATOS

PROFESOR:

JUAN JAIRO LOZANO CARVAJAL

ESTUDIANTES:

ESTEBIL GOMEZ MONTOYA

ID:000272349

BRAHANYAN GABRIEL DIAZ MORENO

ID:000227869

CORPORACIÓN UNIVERSITARIA MINUTO DE DIOS

GIRARDOT

(2020)
1. CREAR APLICACIÓN JAVA AA4, LUEGO CREAR UN JAVA CLASS Y
GUARDAR EN LLAMARLA CALCULADORA, LUEGO COPILAMOS LA
SIGUIENTE LÍNEA DE CÓDIGO.

• APLICACIÓN JAVA AA4

• LINEA DE CODIGO CALCULADORA.

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Calculadora extends Remote{

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


public int mul (int a, int b) throws RemoteException;
public int sub (int a, int b) throws RemoteException;
public int add (int a, int b) throws RemoteException;

}
• PANTALLAZO DE LIENA DE CODIGO.

2. DENTRO APLICACIÓN JAVA AA4 CREAR UNA JAVA CLASS LLAMADA


RMI, LUEGO COPILAMOS LA SIGUIENTE LÍNEA DE CÓDIGO.

• CREACION JAVA CLASS RMI.

• LINEA DE CODIGO RMI.

package aa4;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class rmi extends UnicastRemoteObject implements


Calculadora{
public rmi() throws RemoteException{
int a,b;
}
public int add( int a, int b) throws RemoteException{
return a + b;
}
public int sub( int a, int b) throws RemoteException{
return a - b;
}
public int mul( int a, int b) throws RemoteException{
return a * b;
}
public int div( int a, int b) throws RemoteException{
return a / b;
}
}

• PANTALLAZO.
3. DENTRO APLICACIÓN JAVA AA4 CREAR UNA JAVA CLASS LLAMADA
SERVIDOR, LUEGO COPILAMOS LA SIGUIENTE LÍNEA DE CÓDIGO.

• CREACION JAVA CLASS.

• LINEA DE CODIGO SERVIDOR.

package aa4;

import java.rmi.registry.Registry;
import javax.swing.JOptionPane;
public class Servidor {
public static void main(String[] args) {
try{
Registry r =
java.rmi.registry.LocateRegistry.createRegistry(1099);
r.rebind("Calculadora", new rmi());
JOptionPane.showMessageDialog(null, "Servidor Conectado");
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Servidor no
Conectado" + e);
}
}

}
• PANTALLAZO SERVIDOR.

4. DENTRO APLICACIÓN JAVA AA4 CREAR UNA JAVA CLASS LLAMADA


CLIENTE, LUEGO COPILAMOS LA SIGUIENTE LÍNEA DE CÓDIGO.

• LINEA DE CODIGO DE CLIENTE.

package aa4;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Cliente {

public static void main(String[] args) {


Scanner sc = 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 \n
*Actividad 4 RMI*\n ")
+"Suma...(1)\n"
+"Resta...(2)\n"
+"Multiplicacion...(3)\n"
+"Divicion...(4)\n"
+"Cancelar para salir";
switch (menu) {
case "1": {
int x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
primer numero"));
int y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero"));

JOptionPane.showMessageDialog(null,"La Suma es: "


+c.add(x,y));
break;
}
case "2": {
int x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese
el primer numero"));
int y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero"));

JOptionPane.showMessageDialog(null,"La Resta es: "


+c.sub(x,y));
break;

}
case "3": {
int x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese
el primer numero"));
int y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero"));
JOptionPane.showMessageDialog(null,"La Multiplicacion es: "
+c.mul(x,y));
break;

}
case "4": {
int x = Integer.parseInt(JOptionPane.showInputDialog("Ingrese
el primer numero"));
int y = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
segundo numero"));

JOptionPane.showMessageDialog(null,"La Divicion es: "


+c.div(x,y));
break;
}
}

}
}catch(Exception e) {
System.out.println("Servidor no conectado" + e);
}
}
}

5. POR ÚLTIMO, PONEMOS A CORRER EL SERVIDOR Y EL CLIENTE

• CORREMOR LA CLASS SERVIDOR, NOS ARROJA UN MENSAJE DONDE NOS DICE QUE
EL SERVIDOR ESTA CONECTADO Y LE DAMOS ACEPTAR.
• CORREMOR LA CLASS CLIENTE, NOS ARROJA UN MENSAJE DONDE NOS BIRNDAN
UNAS OPCIONES, SUMA ES IGUAL 1, RESTA A 2, MULTIPLICACION A 3, DIVICION A 4
Y CANCELAR PARA SALIR.

• ESTE ESTE CASO PROCEDEREMOS CON LA SUMA DADO 1 EN LA CAJA DE TEXTO.


6. REFERENCIAS

• CALCULADORA JAVA RMI :


https://www.youtube.com/watch?v=Kn9q7Ro9Re0

Potrebbero piacerti anche