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. Program to compare Strings by compring successive corresponding characters, starting with the first character in each String

  2. Program of linear search

  3. Program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7

  4. Program to show an example of Calling a Base Class Method from a Derived Class

  5. Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back

  6. Program that demonstrates type casting

  7. Program to find a factorial of a given number

  8. Program to print a string on Standard Output Device

  9. Program to show an example of using a Static Nested Class

  10. Develop a CORBA application that takes a string from client and returns whether it is palindrome

  11. Program to read bytes from a file

  12. Program to show the use of Comparison operator (==) for comparing Strings

  13. Program to display text

  14. Program of UDP datagram

  15. An applet program to draw concentric circle in center of the canvas

  16. Program of insertion sort

  17. Encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time after each word in the sent

  18. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

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

  20. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

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