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. An applet program to display sum of two number of textField

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

  3. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

  4. CORBA based application for addition of two mathematical expressions of the form (ax + by) and displaying the result on client side

  5. program which takes a long sentence from the client passes to the server,server separates out each word and sends them back to client in reverse order

  6. File handling program to count number of characters in a file

  7. Program to read input from the Standard Input Device

  8. Program to show some properties of StringBuffer object

  9. Program to show the use of Logical AND Operator (&) in If Statements

  10. File handling program to display directory contents

  11. Program to show the use of Nested Loops

  12. An applet program of linear sort

  13. Develop a RMI based application for addition of two complex numbers

  14. An applet program to display Horizontal Color Bar

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

  16. Program that will count the number of lines in each file that is specified on the command line

  17. Program to compare Strings by compring successive corresponding characters, starting with the first character in each String

  18. Program to show an example of Arrays of String

  19. Program of an applet to illustrate BarChart

  20. Program which calls the method sort(int []a) which throws the Exception ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException

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