//----------------------------------------------------------------------------
// Ex1.java - recapitulatif

//----------------------------------------------------------------------------
class Compte {

    static int nbMaxComptes;
    static Compte[] lesComptes;
    static int nbComptes;

    static double taux;

    int numero;
    int solde;
    int salaire;

    Compte(int n, int sol, int sal) {
	this.numero = n;
	this.solde = sol;
	this.salaire = sal;
	lesComptes[nbComptes] = this;
	nbComptes++;
    }

    static double autorisation(Compte c) {
	return c.salaire * taux;
    }

    static void afficher(Compte c) {
	System.out.println("cpte: "+c.numero+
			   ", solde: "+c.solde+
			   ", sal:  "+c.salaire+
			   ", autor: "+autorisation(c));
    }
    
    static void saisirTaux(String[] args) {
	taux = Double.parseDouble(args[0]);
    }
    
    static void afficherTaux() {
	System.out.println("taux: "+taux);
    }

    static void initialiserLesComptes() {
	nbMaxComptes = 100; 
	nbComptes = 0;
	lesComptes = new Compte[nbMaxComptes];
    }

    static void afficherLesComptes() {
	for (int i=0; i<Compte.nbComptes; i++)
	    afficher(lesComptes[i]);
    }
}
 
//----------------------------------------------------------------------------
class CompteNegocie {

    // Remarque : Dans cette classe, absolument tout est duplique de Compte. 
    // On verra avec l'heritage comment supprimer certaines duplications,
    // et de meme avec la redefinition. 

    static int nbMaxComptesNegocies;
    static CompteNegocie[] lesComptesNegocies;
    static int nbComptesNegocies;

    int numero;
    int solde;
    int salaire;
    int base;

    CompteNegocie(int n, int sol, int sal, int b) {
	this.numero = n;
	this.solde = sol;
	this.salaire = sal;
	this.base = b;
	lesComptesNegocies[nbComptesNegocies] = this;
	nbComptesNegocies++;
    }

    static double autorisation(CompteNegocie c) {
	return (c.salaire * Compte.taux) + c.base;
    }

    static void afficher(CompteNegocie c) {
	System.out.println("cpte neg: "+c.numero+
			   ", solde: "+c.solde+
			   ", sal: "+c.salaire+
			   ", base: "+c.base+
			   ", autor: "+autorisation(c));
    }
    
    static void initialiserLesComptesNegocies() {
	nbMaxComptesNegocies = 100; 
	nbComptesNegocies = 0;
	lesComptesNegocies = new CompteNegocie[nbMaxComptesNegocies];
    }

    static void remplirLesComptesNegocies() {
	new CompteNegocie(5, 5000, 500, 50);
	new CompteNegocie(6, 6000, 600, 60);
    }

    static void afficherLesComptesNegocies() {
	for (int i=0; i<CompteNegocie.nbComptesNegocies; i++)
	    afficher(lesComptesNegocies[i]);
    }
}
 
//---------------------------------------------------------------------------
class Client {

    static int nbMaxClients;
    static Client[] lesClients;
    static int nbClients;

    String nom;
    String ville;
    Compte compte;

    Client(String n, String v, Compte c) {
	this.nom = n;
	this.ville = v;
	this.compte = c;
	lesClients[nbClients] = this;
	nbClients++;
    }

    static void afficher(Client c) {
	System.out.print("nom: "+c.nom+", ville: "+c.ville+", "); 
	Compte.afficher(c.compte);
    }

    static void initialiserLesClients() {
	nbMaxClients = 100; 
	nbClients = 0;
	lesClients = new Client[nbMaxClients];
    }

    static void saisirLesClientsEtLesComptes(String[] args) {
	for (int i=0; i<(args.length-1)/13; i++)
	    new Client(args[13*i+1], args[13*i+2], 
		       new Compte(Integer.parseInt(args[13*i+5]), 
				  Integer.parseInt(args[13*i+6]), 
				  Integer.parseInt(args[13*i+7])));
    }
    
    static void afficherLesClients() {
	for (int i=0; i<Client.nbClients; i++)
	    afficher(lesClients[i]);
    }
    
    static double autorisationMax() {
	double max = Compte.autorisation(lesClients[0].compte);
	for (int i=0; i<Client.nbClients; i++) {
	    double tmp = Compte.autorisation(lesClients[i].compte);
	    if (tmp>max)
		max = tmp;
	}
	return max;
    }
    
    static void afficherAutorisationMax() {
	System.out.println("autorisation max: "+autorisationMax());
    }
}
 
//---------------------------------------------------------------------------
class Ex1 {
    public static void main(String[] args) {

	Compte.saisirTaux(args);
	Compte.initialiserLesComptes();
	CompteNegocie.initialiserLesComptesNegocies();
	Client.initialiserLesClients();
	Client.saisirLesClientsEtLesComptes(args);
	CompteNegocie.remplirLesComptesNegocies();

	Compte.afficherTaux();
	Compte.afficherLesComptes();
	CompteNegocie.afficherLesComptesNegocies();
	Client.afficherLesClients();

	Client.afficherAutorisationMax();
    }   
}

//---------------------------------------------------------------------------
/*
  java Ex1 0.1 Riton Paname 2 0 1 1000 100 -1 0 2 2000 200 -1 Lulu NewYork 2 1 3 3000 300 30 0 4 4000 400 -1
  taux: 0.1
  cpte: 1, solde: 1000, sal:  100, autor: 10.0
  cpte: 3, solde: 3000, sal:  300, autor: 30.0
  cpte neg: 5, solde: 5000, sal: 500, base: 50, autor: 100.0
  cpte neg: 6, solde: 6000, sal: 600, base: 60, autor: 120.0
  nom: Riton, ville: Paname, cpte: 1, solde: 1000, sal:  100, autor: 10.0
  nom: Lulu, ville: NewYork, cpte: 3, solde: 3000, sal:  300, autor: 30.0
  autorisation max: 30.0
*/

//---------------------------------------------------------------------------
