Java Tutorial

 
 
 
 
// IDL

module GameModule
{
    interface Game
    {
        double guess(in double operand1);
    };

};


// GameImpl
// Contains the implementation of the methods defined in the IDL file.

import GameModule.GamePOA;

class GameImpl extends GamePOA
{
    GameImpl()
    {
        super();
        System.out.println(\"game Object Created\");
    }

    public double guess(double num)
    {
        if(num < 50)
            return(-1);
        else if(num > 50)
            return(1);
        else
            return(0);
    }
}


// OUTPUT

1
1
You enter number is Lower
Enter no=
32
32
You enter number is Lower
Enter no=
34
34
You enter number is Lower
Enter no=
65
65
You enter number is Higher
Enter no=
99
99
You enter number is Higher
Enter no=
50
50
You enter Exact num in trial =5


// Server


import GameModule.Game;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;

class GameServer
{

    public static void main(String[] args)
    {
        try
        {
            // initialize the ORB
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);

            // initialize the BOA/POA
            POA rootPOA = POAHelper.narrow(orb.resolve_initial_references(\"RootPOA\"));
            rootPOA.the_POAManager().activate();

            // creating the calculator object
            GameImpl game = new GameImpl();

            // get the object reference from the servant class
            org.omg.CORBA.Object ref = rootPOA.servant_to_reference(game);

            System.out.println(\"Step1\");
            Game h_ref = GameModule.GameHelper.narrow(ref);
            System.out.println(\"Step2\");

            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");
            System.out.println(\"Step3\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
            System.out.println(\"Step4\");

            String name = \"Game\";
            NameComponent path[] = ncRef.to_name(name);
            ncRef.rebind(path,h_ref);

            System.out.println(\"Game Server reading and waiting....\");
            orb.run();


        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


// Client

import GameModule.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.DataInputStream;
import java.lang.Integer;

class GameClient
{

    public static void main(String args[])
    {
        Game GameImpl=null;
        int count=0;
        int data;
        try
        {
            // initialize the ORB
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);

            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

            String name = \"Game\";
            GameImpl = GameHelper.narrow(ncRef.resolve_str(name));

            while(true)
            {
            int num;
            System.out.println(\"Enter no=\");
            DataInputStream in=new DataInputStream(System.in);
            num=Integer.parseInt(in.readLine());
            System.out.println(num);

             data=(int) GameImpl.guess(num);
                if(data == -1)
                {
                    System.out.println(\"You enter number is Lower\");
                    count=count+1;
                }
                else if(data == 1)
                {
                    System.out.println(\"You enter number is Higher\");
                    count=count+1;
                }
                else if(data == 0)
                {
                    System.out.println(\"You enter Exact num in trial =\"+count);
                    break;
                }
            }


        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }


}

    Related Post:
  1. RMI based application, which reads a file with list of marks of student from a client, send it to server and find how many students having distinct

  2. Program to show an example of using user-defined package in a program

  3. Program to show an example of using a Static Nested Class outside the Top-Level Class

  4. CORBA PROGRAM TO GET THE HTML CODE FROM ANY URL

  5. An applet program of linear sort

  6. Program to declare and initialize Boolean variables and print them on the Standard Output Device

  7. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

  8. Program that accepts a shopping list of five items from the command line and stores them in vector

  9. Program to show the use of While Loop

  10. Program to show the use of Conditional AND Operator (&&) in If Statements

  11. Program to show the use of Bitwise Operator (~) Complement

  12. Program to make directory

  13. Program to compute the sum of the digits of a given integer number. eg: I/o=4 then O/p=4+3+2+1=10

  14. Corba program of Count Client Applet, IDL,Server, Client

  15. Program which creates an Array of character. Make one function with one argument as a character and that function throw a user defined exception

  16. Program to show the comparing of Strings for equality

  17. An applet program to display moving banner

  18. Program that demonstrates type casting

  19. Program of inventory management and demonstrating interactive input and output

  20. Biological Sequence Allignment Using Dynamic Programing

 
 
Didn't find what you were looking for? Find more on Corba program of game