MAIN MENU BIODATA ASSIGNMENTS TUTORIALS EMAILS
DISTRIBUTED SYSTEMS (TCT 2034)
ASSIGNMENT 4
( RMI )
QUESTION:
Do computation for loans. In the interface insert 3 things that is principal, rate and time. Calculate the interest and how much must pay for each month.
import java.rmi.;
public interface Loan extends Remote
{
public int getInterest() throws RemoteException;
public int getPrincipal() throws RemoteException;
public int getRate() throws RemoteException;
public int getTime() throws RemoteException;
}
----------------------------------------------------------------------------------------------------------------------------------------------------
import java. rmi.*;
import java.rmi.server.*;
public class LoanImpl extends UnicastRemoteObject implements Loan
{
private double interest;
private int principal;
private double rate;
private int time;
//Constructor for implementation objects...
public LoanImpl (double i,int p, double r, int t) throws Remoteexception
{
interest = i;
principal = p;
rate = r;
time = t;
}
public int getInterest() throws RemoteException
{
return interest;
}
public int getPrincipal() throws RemoteException
{
return principal;
}
public int getRate() throws RemoteException
{
return principal;
}
public int getTime() throws RemoteException
{
return time;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------
import java.rmi.*;
public class LoanServer
{
private static final String HOST = "localhost";
public static void main(String[] args) throws Exception
{
//Create array of initialized implementation objects...
LoanImpl[] interest =
{new LoanImpl(10,000,"4/100",5),
new LoanImpl(12,000,"4/100",5),
new LoanImpl(15,000,"4/100",5)};
for (int=0; i<interest.length; i++)
{
int interestCount = interest[i].getInterestCount();
//Generate each account name (as a concatenation
//of 'Interest' and the interest count) and bind
//it to the appropriate object refernce in the
//array...
naming.rebind("rmi://+HOST + "/Interest"
+interestCount, interest[i]);
}
System.out.println("Binding complete...\n");
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------
import java.rmi.*;
public class LoanClient
{
private static final String HOST = “localhost”;
private static final int[] loanInterest =
{10,000,12,000,15,000};
public static void main (String[] args)
{
try
{
//Simply display all loan details…
for(int=0; i<loanInterest.length; i++)
{
//Obtain a reference to the object from the
//registry and typecast it into the appropriate
//type…
Loan temp = (Loan)Naming.lookup(“rmi://”+
HOST + “/Loan” + loanInterest[i]);
//Now invoke the methods of the interface to
//display details of the associated loan…
System.out.println(“\nLoan Principal: “
+ temp.getPrincipal());
System.out.println(“\nLoan Rate: “
+ temp.getRate());
System.out.println(“\nLoan Time: “
+ temp.getTime());
}
}
catch(ConnectException conEx)
{
System.out.println(“Unable to connect to server!”);
System.exit(1);
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT