CORBA - CELCIUS TO FARENHEIT CONVERSION


AIM:
    To write a Java program for the implementation of celcius to farenheit using CORBA.

ALGORITHM:

SERVER SIDE:
Step 1: Start
Step 2: Define the class Tempcalcserver
Step 3: Create & Initialize the objects orb, tempImpl, objRef, ncRef, path[] in try
Step 4: Connect the object tempImpl
Step 5: Rebind the objects path, tempImpl
Step 6: Make ready the Tempconv server
Step 7: Call the method printStackTrace() in catch
Step 8: Stop

CLIENT SIDE:
Step 1: Start
Step 2: Define the class Tempcalcclient
Step 3: Declare the objects din, orb, ncRef path[], calc in try
Step 4: Read the celcius
Step 5: Display the temperature in farenheit by calling the method celcius()
Step 6: Call the method printStackTrace() in catch
Step 7: Stop

SOURCE CODE:

Tempcalc.idl
module Tempconvcalc
{

interface Tempcalc
{
double get_celcius(in string symbol);
};
};

TempcalcImp.java
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import Tempconvcalc.*;
public class TempcalcImp extends _TempcalcImplBase
{
public double get_celcius(String symbol)
{
double celcius=Double.parseDouble(symbol);
double farenheit=1.8*celcius+32;
return farenheit;
}
public TempcalcImp()
{
super();
}
}

Tempcalcclient.java
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import Tempconvcalc.*;
import java.io.DataInputStream;
public class Tempcalcclient
{
public static void main(String args[])
{
try
{
DataInputStream din=new DataInputStream(System.in);
ORB orb=ORB.init(args,null);
NamingContext ncRef=NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
NameComponent path[]={new NameComponent("TEMPCALC","")};
Tempcalc calc=TempcalcHelper.narrow(ncRef.resolve(path));
System.out.println("\nEnter the celcius:");
String cel=din.readLine();
System.out.println("\nTemparature of the city in farenhit is "+calc.get_celcius(cel));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Tempcalcserver.java
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import Tempconvcalc.*;
public class Tempcalcserver
{
public static void main(String args[])
{
try
{
ORB orb=ORB.init(args,null);
TempcalcImp tempImpl=new TempcalcImp();
orb.connect(tempImpl);
org.omg.CORBA.Object objref=orb.resolve_initial_references("NameService");
NamingContext ncRef=NamingContextHelper.narrow(objref);
NameComponent nc=new NameComponent("TEMPCALC","");
NameComponent path[]={nc};
ncRef.rebind(path,tempImpl);
System.out.println("Tempconv server is ready");
Thread.currentThread().join();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

OUTPUT:

SERVER SIDE:


 CLIENT SIDE:



RESULT:
          Thus the Java program for the conversion of celcius to farenheit was performed and the output was verified.

.
Previous
Next Post »

Still not found what you are looking for? Try again here.