Logo 
Search:

Java Articles

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

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

Posted By: Milind Mishra     Category: Java     Views: 8567

Develop an 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
distinction, first class, second class and fail and display the result on
client side.

Code for 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 in Java

// ResultRmi Interfacepublicinterface ResultRMI extends java.rmi.Remote
{
    String calcresult(double marks[],int count) throws java.rmi.RemoteException;
}


// ResultRMIImpl.java, ResultRMI implementation

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

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

  public String calcresult(double marks[],int count) throws RemoteException
  { 
    double total=0.0,average;
    for(int i=0;i<count;i++)
    {
        total=total+marks[i];
    }
    average = total/count;
    if(average >= 70)
    {
        return"Distinction";
    }
    elseif(average >=60 && average < 70)
    {
        return"Firstclass";
    }
    elseif(average >=50 && average < 60)
    {
        return"secondclass";
    }
    elseif(average >=40 && average <50)
    {
        return"passcalss";
    }
    else 
    {
        return"fail";
    }

  }
}


// ResultRMIServer.java

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

publicclass ResultRMIServer
{

 publicstaticvoid main(String args[])
 {

   // Create and install the security manager
   System.setSecurityManager(new RMISecurityManager());

   try
   {
     // Create ResultRMIImpl
     ResultRMIImpl myResult = new ResultRMIImpl("//Binita/myResultRMI");
     System.out.println("ResultRMI Server ready.");
   } 
   catch (Exception e)
   { 
     System.out.println("Exception: " + e.getMessage());
     e.printStackTrace();
   }
 }
}


// ResultRMIClient.java  RMI Result client

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

publicclass ResultRMIClient
{ publicstaticvoid main(String args[]) throws Exception
  { 
    // Create and install the security manager
    System.setSecurityManager(new RMISecurityManager());
    
    FileReader fr = new FileReader("studentdetails.txt");
    StreamTokenizer tok = new StreamTokenizer(fr);
    String name="",classval,s;
    double marks[] = newdouble[10];
    int i=0;
    tok.eolIsSignificant(true);
    try
    { 
        ResultRMI myResult = (ResultRMI)Naming.lookup("//"
                          + args[0] + "/" + "myResultRMI");
    
        while( tok.nextToken() != tok.TT_EOF)
    {
        
        if(tok.ttype == tok.TT_WORD)
        {
            name = tok.sval;
            System.out.println("\nname is:"+name);
            System.out.println("Obtained marks are:");
        }
        
        if(tok.ttype == tok.TT_NUMBER)
        {
        
            marks[i] = tok.nval;    
            System.out.println("Marks of subject "+i +" is "+marks[i]);
            i++;

        }    
        if(tok.ttype == tok.TT_EOL && tok.ttype != tok.TT_EOF)
        {
            classval = myResult.calcresult(marks,i);
            System.out.println(name +" has " + classval);
            i=0;
            
        }     
    }
    
    fr.close();
    
    } 
    catch(Exception e)
    { 
        System.err.println("System Exception" + e);
    }
   System.exit(0);
  }
}


// OUTPUT

-----  studentdetails.txt  ------

binita 45 56 74 68
rasesh 88 85 96 92
krupa 41 42 51 52
nauka 62 53 62 48
rinkal 35 38 41 40
--------------------




name is:binita
Obtained marks are:
Marks of subject 0 is 45.0
Marks of subject 1 is 56.0
Marks of subject 2 is 74.0
Marks of subject 3 is 68.0
binita has Firstclass

name is:rasesh
Obtained marks are:
Marks of subject 0 is 88.0
Marks of subject 1 is 85.0
Marks of subject 2 is 96.0
Marks of subject 3 is 92.0
rasesh has Distinction

name is:krupa
Obtained marks are:
Marks of subject 0 is 41.0
Marks of subject 1 is 42.0
Marks of subject 2 is 51.0
Marks of subject 3 is 52.0
krupa has passcalss

name is:nauka
Obtained marks are:
Marks of subject 0 is 62.0
Marks of subject 1 is 53.0
Marks of subject 2 is 62.0
Marks of subject 3 is 48.0
nauka has secondclass

name is:rinkal
Obtained marks are:
Marks of subject 0 is 35.0
Marks of subject 1 is 38.0
Marks of subject 2 is 41.0
Marks of subject 3 is 40.0
rinkal has fail
  
Share: 



Milind Mishra
Milind Mishra author of 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 is from India.
 
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!