Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Remote Method InvocationRSS Feeds

Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained

Posted By: Blasa Fischer     Category: Java     Views: 4674

Write a RMI based application which takes your marks of six subjects from the client side and displays the percentage that you have obtained.

Code for Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained in Java

----------------------------------------------------------------------------------
                    Interface
----------------------------------------------------------------------------------
publicinterface perInterface extends java.rmi.Remote

{
    float find_per(int marks[]) throws java.rmi.RemoteException;
}


-------------------------------------------------------------------------------------------------
                    Implementation
-------------------------------------------------------------------------------------------------

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;

publicclass perImpl extends UnicastRemoteObject
               implements perInterface
{
    public perImpl(String name) throws RemoteException
    {
        super();
        try
        {
            Naming.rebind(name,this);
        }
        catch(Exception e) 
        { 
            System.out.println("Exception:"+ e.getMessage());
            e.printStackTrace();
        }
    }

    publicfloat find_per(int marks[]) throws RemoteException
    {
        int sum=0;
        float per;

        for(int counter=0;counter < marks.length;counter++)
            sum+=marks[counter];

        per = (float)sum/3;

        return per;
    }

}

-------------------------------------------------------------------------------------------------
                    Client
-------------------------------------------------------------------------------------------------

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.io.*;

publicclass perClient
{
    publicstaticvoid main(String args[])
    {
        System.setSecurityManager(new RMISecurityManager());

        try
        {
            float percentage=0;
            int marks[]=newint[6];

            perInterface pi = (perInterface) Naming.lookup("//localhost/pno");

            BufferedReader ber=new BufferedReader(new InputStreamReader(System.in));
            String temp=new String();

            for(int counter=0;counter<6;counter++)
            {
                System.out.print("\n Enter Marks For Subject " + (counter+1) + " : ");
                temp=ber.readLine();
                marks[counter]=Integer.parseInt(temp);
            }


            percentage = pi.find_per(marks);
            System.out.println("Percentage is : " + percentage);

        }
        catch(Exception e)
        {
            System.out.println("System Exception" + e);
        }
    }
}


-------------------------------------------------------------------------------------------------
                    Server
-------------------------------------------------------------------------------------------------

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

publicclass perServer
{
    publicstaticvoid main(String args[])
    {
        System.setSecurityManager(new RMISecurityManager());

        try
        {
            perImpl pim = new perImpl("//localhost/pno");
            System.out.println("\nServer is ready...");
        }
        catch(Exception e) 
        { 
            System.out.println("Exception: " + e.getMessage());
            e.printStackTrace();
        }
    }
}    


-------------------------------------------------------------------------------------------------
                    Policy
-------------------------------------------------------------------------------------------------

grant
{
    // Allow everything for now
    permission java.security.AllPermission;
};

----------------------------------------------------------------------------------
                    Output
----------------------------------------------------------------------------------


 Enter Marks For Subject 1 : 30

 Enter Marks For Subject 2 : 25

 Enter Marks For Subject 3 : 28

 Enter Marks For Subject 4 : 21

 Enter Marks For Subject 5 : 29

 Enter Marks For Subject 6 : 22
Percentage is : 51.666668
  
Share: 



Blasa Fischer
Blasa Fischer author of Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!