0% found this document useful (0 votes)
20 views6 pages

Rmi Java Code Temp

remote method invocation

Uploaded by

tomas umer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views6 pages

Rmi Java Code Temp

remote method invocation

Uploaded by

tomas umer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Exercise 3: Write a RMI program to convert temperature in Celsius to Fahrenheit and

vice versa.

Interface:

import java.rmi.*;
public interface Tempintf extends Remote
{
double cen_fah(double c) throws RemoteException;
double fah_cen(double f)throws RemoteException;
}

Implementation:

import java.rmi.*;
import java.rmi.server.*;
public class TempConvert extends UnicastRemoteObject implements Tempintf
{
public double cen_fah(double c)throws RemoteException
{
double f=c*1.8+32;
return f;
}
public double fah_cen(double f)throws RemoteException
{
double c=(f-32)/1.8;
return c;
}
public TempConvert() throws RemoteException{};
}

Server:

import java.rmi.*;
import java.net.*;
public class TempServer
{
public static void main(String args[])
{
try
{
TempConvert t=new TempConvert();
Naming.rebind("TempSever",t);
}
catch(Exception e)
{}
}
}

Client:
import java.rmi.*;
import java.io.*;
public class TempClient
{
public static void main(String args[])
{
try
{
DataInputStream in=new DataInputStream(System.in);
Tempintf t=(Tempintf)Naming.lookup("rmi://localhost/TempServer");
System.out.println("Temperature converion");
System.out.println("Enter Celsius Temperature");
float c=Float.valueOf(in.readLine());
System.out.println("Fehrenhit value is: "+t.cen_fah(c));
System.out.println("Enter Fahrenhit Temperature");
float f=Float.valueOf(in.readLine());
System.out.println("Celsius value is: "+t.fah_cen(f));
}
catch(Exception e)
{}
}
}

OUTPUT:
Exercise 4: Write a RMI program to calculate interest on particular amount.

Interface:

import java.rmi.*;
public interface Simpleintf extends Remote
{
double simplecal(double p,double t,double r)throws RemoteException;
}

Implementation:
import java.rmi.*;
import java.rmi.server.*;
public class Simpleimp extends UnicastRemoteObject implements Simpleintf
{
public double simplecal(double p,double t,double r)throws RemoteException
{
double si=(p*t*r)/100;
return si;
}
public Simpleimp() throws RemoteException{};
}

Server:

import java.rmi.*;
import java.net.*;
public class SimpleServer{
public static void main(String args[]){
try{
Simpleimp s=new Simpleimp();
Naming.rebind("SimpleServer",s);
}
catch(Exception e)
{}
}
}

Client:
import java.rmi.*;
import java.io.*;
public class SimpleClient
{
public static void main (String args[]){
try{
DataInputStream in=new DataInputStream(System.in);
Simpleintf s=(Simpleintf)Naming.lookup("rmi://localhost/SimpleServer");
System.out.println("Simple Interest");
System.out.println("Enter Principle Amount:");
double p=Double.valueOf(in.readLine());
System.out.println("Enter time:");
double t=Double.valueOf(in.readLine());
System.out.println("Enter Rate of Interest:");
double r=Double.valueOf(in.readLine());
System.out.println("Simple Interest is:"+s.simplecal(p,t,r));
}
catch(Exception e)
{}
}
}
OUTPUT:

You might also like