- Interface
-
- /**
- * @(#)MyInterface.java
- *
- *
- * @author serge toure
- * @version 1.00 2008/5/6
- */
- import java.rmi.*;
-
- public interface MyInt extends Remote {
-
- public int checkpiece(int piece) throws RemoteException;
- public String bilan()throws RemoteException;
- public String checkforchange() throws RemoteException;
- public void init()throws RemoteException;
- public int totalDebit(int cb,int chq,int virmt) throws RemoteException;
- public float percent(int val, int total) throws RemoteException;
-
- }
-
-
- Le serveur
-
- /**
- * @(#)MyserverImpl.java
- *
- *
- * @author serge toure
- * @version 1.00 2008/5/6
- */
-
- import java.rmi.server.*;
- import java.rmi.*;
- import java.net.*;
-
-
-
- public class servImpl extends UnicastRemoteObject implements MyInt {
-
-
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- int nbPiece1F=0;int nbPiece2F=0;int nbPiece5F=0;
- int totalRecu=0;
-
- public servImpl() throws RemoteException {
- super();
- }
-
-
-
-
-
- public int checkpiece(int piece) throws RemoteException{
-
-
- switch(piece){
- case 1:
- nbPiece1F=nbPiece1F+1;
- break;
- case 2:
- nbPiece2F=nbPiece2F+1;
- break;
- case 5:
- nbPiece5F=nbPiece5F+1;
- break;
- default:
- piece=0;
-
- }
- totalRecu=totalRecu+piece;
- return totalRecu;
- }
-
- public String bilan() throws RemoteException{
-
- return ("Vous avez entrés:\n"+
- +nbPiece1F+" piece(s) de 1F \n"
- +nbPiece2F+" piece(s) de 2F \n"
- +nbPiece5F+" piece(s) de 5F \n"
- +"Soit un total de :"+totalRecu+ "F\n"
-
-
- +"Je vous serre un cafe");
- }
-
-
-
-
-
-
-
- public String checkforchange() throws RemoteException{
- int change=0;
- if(totalRecu>3)
- change=totalRecu-3;
- return "Et je vous rends la monnaie de valeur:"+change+"F";
-
- }
-
- public void init()throws RemoteException{
-
- nbPiece1F=0;
- nbPiece2F=0;
- nbPiece5F=0;
- totalRecu=0;
-
-
- }
-
- public int totalDebit(int cb,int chq,int virmt) throws RemoteException{
-
- int nbDebit=0;
- nbDebit=cb+chq+virmt;
- return nbDebit;
- }
-
- public float percent(int val, int total) throws RemoteException{
-
- float prct=0;
- prct=(float)(val *100/total);
- return prct;
- }
-
-
-
-
-
- public static void main (String[]args){
-
- try{
- servImpl s=new servImpl();
- Naming.rebind("myserver",s);
- System.out.println("Server ready to work now!");
- }
- catch(RemoteException e){
- System.out.println("RemoteException "+ e);
- }
- catch(MalformedURLException e){
- System.out.println("Malformed "+e);
- }
- }
-
-
- }
-
-
- Le client
-
- /**
- * @(#)Myclient.java
- *
- *
- * @author serge toure
- * @version 1.00 2008/5/6
- */
-
-
- import java.rmi.*;
- public class Monclient {
-
-
- public static void main(String[]args) {
- int piece,total;
- char rep='o';
- String mess1,mess2;
- int nbCb=0,nbChq=0,nbVirmt=0,nbDebit=0;
- float prctCb=0,prctChq=0,prctVirmt=0;
- try{
- MyInt n=(MyInt)Naming.lookup("rmi://sergetoure:1099/myserver");
- System.out.println("");
- System.out.println("");
- System.out.println("");
- System.out.println("************************Bienvenue au cafe monnaie!******************************");
-
- do{
-
- System.out.println("Entrer au moins 3F pour obtenir un cafe");
- System.out.println("Les pieces acceptées sont:1F,2F et 5F");
- do{
- piece=Lire.i();
- if((piece!=1)&& (piece!=2 )&&( piece!=5)){
-
- System.out.println("Veuillez entrer une piece de 1F,2F ou de 5F SVP!");}
- total=n.checkpiece(piece);
- }while(total<3);
- mess1=n.bilan();
- System.out.println(mess1);
- mess2=n.checkforchange();
- System.out.println(mess2);
-
- n.init();
-
- System.out.println("Voulez vous en un autre? o/n");
- do{
- System.out.println("Entrer 'o' pour continuer et 'n' pour quitter!");
-
- rep=Lire.c();
-
- }while ((rep!='o')&&(rep!='n'));
-
- }while(rep=='o');
- System.out.println("Merci d'avoir utilise cafe monnaie *BONNE JOURNEE A VOUS*");
- System.out.println("");
- System.out.println("");
- System.out.println("");
-
-
- System.out.println("*********************STATISTIQUE*****************************");
-
-
- System.out.println("Nombre de paiements par carte bleue: ");
- nbCb=Lire.i();
-
- System.out.println("Nombre de paiements par chèque: ");
- nbChq=Lire.i();
-
- System.out.println("Nombre de paiements par virements: ");
- nbVirmt=Lire.i();
-
- nbDebit=n.totalDebit(nbCb,nbChq,nbVirmt);
-
- prctCb=n.percent(nbCb,nbDebit);
- prctChq=n.percent(nbChq,nbDebit);
- prctVirmt=n.percent(nbVirmt,nbDebit);
-
-
- System.out.println("Nombre total d'ordres de débits emis:"+nbDebit);
- System.out.println("Pourcentage de paiements par carte bleue: "+prctCb +"%");
- System.out.println("Pourcentage de paiements par chèques: "+prctChq+ "%");
- System.out.println("Pourcentage de paiements par virements: "+prctVirmt+ "%");
-
-
- }
- catch(Exception e){
- System.out.println("Exception :"+e);
- }
- }
- }
Interface
/**
* @(#)MyInterface.java
*
*
* @author serge toure
* @version 1.00 2008/5/6
*/
import java.rmi.*;
public interface MyInt extends Remote {
public int checkpiece(int piece) throws RemoteException;
public String bilan()throws RemoteException;
public String checkforchange() throws RemoteException;
public void init()throws RemoteException;
public int totalDebit(int cb,int chq,int virmt) throws RemoteException;
public float percent(int val, int total) throws RemoteException;
}
Le serveur
/**
* @(#)MyserverImpl.java
*
*
* @author serge toure
* @version 1.00 2008/5/6
*/
import java.rmi.server.*;
import java.rmi.*;
import java.net.*;
public class servImpl extends UnicastRemoteObject implements MyInt {
/**
*
*/
private static final long serialVersionUID = 1L;
int nbPiece1F=0;int nbPiece2F=0;int nbPiece5F=0;
int totalRecu=0;
public servImpl() throws RemoteException {
super();
}
public int checkpiece(int piece) throws RemoteException{
switch(piece){
case 1:
nbPiece1F=nbPiece1F+1;
break;
case 2:
nbPiece2F=nbPiece2F+1;
break;
case 5:
nbPiece5F=nbPiece5F+1;
break;
default:
piece=0;
}
totalRecu=totalRecu+piece;
return totalRecu;
}
public String bilan() throws RemoteException{
return ("Vous avez entrés:\n"+
+nbPiece1F+" piece(s) de 1F \n"
+nbPiece2F+" piece(s) de 2F \n"
+nbPiece5F+" piece(s) de 5F \n"
+"Soit un total de :"+totalRecu+ "F\n"
+"Je vous serre un cafe");
}
public String checkforchange() throws RemoteException{
int change=0;
if(totalRecu>3)
change=totalRecu-3;
return "Et je vous rends la monnaie de valeur:"+change+"F";
}
public void init()throws RemoteException{
nbPiece1F=0;
nbPiece2F=0;
nbPiece5F=0;
totalRecu=0;
}
public int totalDebit(int cb,int chq,int virmt) throws RemoteException{
int nbDebit=0;
nbDebit=cb+chq+virmt;
return nbDebit;
}
public float percent(int val, int total) throws RemoteException{
float prct=0;
prct=(float)(val *100/total);
return prct;
}
public static void main (String[]args){
try{
servImpl s=new servImpl();
Naming.rebind("myserver",s);
System.out.println("Server ready to work now!");
}
catch(RemoteException e){
System.out.println("RemoteException "+ e);
}
catch(MalformedURLException e){
System.out.println("Malformed "+e);
}
}
}
Le client
/**
* @(#)Myclient.java
*
*
* @author serge toure
* @version 1.00 2008/5/6
*/
import java.rmi.*;
public class Monclient {
public static void main(String[]args) {
int piece,total;
char rep='o';
String mess1,mess2;
int nbCb=0,nbChq=0,nbVirmt=0,nbDebit=0;
float prctCb=0,prctChq=0,prctVirmt=0;
try{
MyInt n=(MyInt)Naming.lookup("rmi://sergetoure:1099/myserver");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("************************Bienvenue au cafe monnaie!******************************");
do{
System.out.println("Entrer au moins 3F pour obtenir un cafe");
System.out.println("Les pieces acceptées sont:1F,2F et 5F");
do{
piece=Lire.i();
if((piece!=1)&& (piece!=2 )&&( piece!=5)){
System.out.println("Veuillez entrer une piece de 1F,2F ou de 5F SVP!");}
total=n.checkpiece(piece);
}while(total<3);
mess1=n.bilan();
System.out.println(mess1);
mess2=n.checkforchange();
System.out.println(mess2);
n.init();
System.out.println("Voulez vous en un autre? o/n");
do{
System.out.println("Entrer 'o' pour continuer et 'n' pour quitter!");
rep=Lire.c();
}while ((rep!='o')&&(rep!='n'));
}while(rep=='o');
System.out.println("Merci d'avoir utilise cafe monnaie *BONNE JOURNEE A VOUS*");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("*********************STATISTIQUE*****************************");
System.out.println("Nombre de paiements par carte bleue: ");
nbCb=Lire.i();
System.out.println("Nombre de paiements par chèque: ");
nbChq=Lire.i();
System.out.println("Nombre de paiements par virements: ");
nbVirmt=Lire.i();
nbDebit=n.totalDebit(nbCb,nbChq,nbVirmt);
prctCb=n.percent(nbCb,nbDebit);
prctChq=n.percent(nbChq,nbDebit);
prctVirmt=n.percent(nbVirmt,nbDebit);
System.out.println("Nombre total d'ordres de débits emis:"+nbDebit);
System.out.println("Pourcentage de paiements par carte bleue: "+prctCb +"%");
System.out.println("Pourcentage de paiements par chèques: "+prctChq+ "%");
System.out.println("Pourcentage de paiements par virements: "+prctVirmt+ "%");
}
catch(Exception e){
System.out.println("Exception :"+e);
}
}
}