IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Java Discussion :

Appelé une class dans le programme main


Sujet :

Langage Java

  1. #1
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut Appelé une class dans le programme main
    J ai cette classe que je veux l'apeller dans un petit programme main je veux appeler la methode generatedatabase(10,true,false).
    Est ce que quelqu'un peut me donner un petit main qui fait ça ???
    Voila la Classe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    package lih.rtdb.simrtdb.generator;
     
    import lih.rtdb.simrtdb.data.*;
    import java.util.*;
     
    /**
     * It is the class that permit to create arrival time using Poisson process
     * @author <a href="mailto:Majed.Abdouli@univ-lehavre.fr">Majed Abdouli</a>
     */
    public class Generator{
     
        private Random generator;
        private GlobalClock refGlobalClock;
     
        /**
         * Default Constructor
         */
        public Generator (GlobalClock refGlobalClock, Random generator){
    	this.generator = generator;
    	this.refGlobalClock = refGlobalClock;
        }
     
        /**
         * Generate a new DataBase 
         * @param numberOfData the number of data item to generate in the database
         * @param data this value permit to specify if non real time data must be generated
         * @param realtimedata this value permit to specify if real time data must be generated
         */
        public DataBase generateDataBase (int numberOfData, 
    				      boolean data, boolean realtimedata){
    	DataBase db = new DataBase (numberOfData, generator);
    	for (int i=0; i<numberOfData; i++) {
    	    if (data && realtimedata)
    		if ((int)(Math.round(generator.nextDouble()))==0)
    		    db.add (Data.generateOne(i));
    		else
    		    db.add (RealTimeData.generateOne(i,1,generator));
    	}
    	return db;
        }
     
        /**
         * Generate a new DataBase 
         * @param numberOfData the number of data item to generate in the database
         * @param maxNumSite the number of site to consider
         * @param data this value permit to specify if non real time data must be generated
         * @param realtimedata this value permit to specify if real time data must be generated
         */
        public DataBase generateDataBase (int numberOfData, int maxNumSite, 
    				      boolean data, boolean realtimedata){
    	DataBase db = new DataBase (numberOfData, generator);
    	for (int i=0; i<numberOfData; i++) {
    	    if (data && realtimedata)
    		if ((int)(Math.round(generator.nextDouble()))==0)
    		    db.add (Data.generateOne(i,maxNumSite,generator));
    		else
    		    db.add (RealTimeData.generateOne(i,maxNumSite,generator));
    	}
    	return db;
        }
     
        /**
         * Generate a new DataBase with Real Time Data
         * @param numberOfData the number of data item to generate in the database
         */ 
        public DataBase generateRealTimeDataBase (int numberOfData){
    	return generateDataBase(numberOfData, false, true);
        }
     
        /**
         * Generate a new Queue of Transaction using the static method Transaction.generateOne()
         */
        public TransactionQueue generateRealTimeTransaction (int lambda, int phenomenon){
    	ArrivalTime aa = new ArrivalTime (lambda,phenomenon,generator);
    	int numberOfTransactions = aa.getNumberOfArrivalTime();
    	TransactionQueue aQueue = new TransactionQueue (numberOfTransactions);
    	for (int i=0; i<numberOfTransactions; i++){
    	    Transaction tr = Transaction.generateOne(i, refGlobalClock, generator);
    	    tr.setArrivalDate (aa.getArrivalTime(i));
    	    aQueue.pushTransaction (tr);
    	}
    	return aQueue;
        }
     
    }

  2. #2
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    salut,
    DataBase c'est une classe que tu as créer toi même?

  3. #3
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    oui
    je veux appeler la methode generateDataBase avec les paramètre 10,true,false dans un main et qu'il soit executable.
    En fait je sait pas comment appelé une class et sa methode dans le main.

  4. #4
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    salut,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    public static void main(String argv[])
    {
    Generator G = new Generator(/*arguements du constructeur*/);
    DataBase db;
    db = G.generatedatabase(10,true,false);
    }
    tu appele cette fonction main dans une classe nouvelle ou dans le coprs de la classe Generator.

  5. #5
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    il me retourne cette erreure :
    exemple.java :8: connot find symbole
    symbole: constructor generator
    generator g = new generator();
    sachant que je l ai mit dans une classe exemple

  6. #6
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    salut,
    c'est normal parce que le constructeur de la classe Generator est de cette format :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Generator(GlobalClock refGlobalClock, Random generator)
    il manque le paramètre de type Random et le paramètre de type GlobalClock.

  7. #7
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    je sait pas quesque je met voila la classe globalclock :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    package lih.rtdb.simrtdb.data;
     
    import java.util.*;
     
    /**
     * This Class is use to represent the time use in all the simulation
     */
    public class GlobalClock {
     
        private int currentTime; 
     
        public GlobalClock (){
    	currentTime = 0;
        }
     
        public void incrementTime () {
    	currentTime++;
        }
     
        public int getCurrentTime (){
    	return currentTime;
        }
     
    }

  8. #8
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    salut,
    essaye
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Generator(new GlobalClock(), ...)
    pour la classe Random tu met aussi son constructeur.

  9. #9
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    j ai crée une class exemple et j ai mit le code si dessous la compilation 5/5 mais l execution ??? erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    package lih.rtdb.simrtdb.generator;
    import lih.rtdb.simrtdb.data.*;
    import java.util.*;
    import java.io.*;
     
    class Exemple{    
        public static void main(String argv[])
    {
    GlobalClock C = new GlobalClock();
    Random R = new Random();
    Generator G =new Generator(C,R);
    DataBase db;
    db = G.generateDataBase(10,true,false);
    System.out.println("bdbdbdbdbdbd");
        System.out.println("Data base crée avec succee");
        }
        }
    Est ce que je peut mettre le main dans la class generator et ou svp ???

  10. #10
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    salut,
    oui tu peut mettre la fonction main dans la classe Generator où tu veut comme les autres fonctions de la classe Generator.
    c'est quoi l'erreur d'éxécution?

  11. #11
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    l erreur c est:
    exeption in thread "main" java.lang.noclassfounderror exemple (wrong name : lih\rtdb\simrtdb\generator\Exemple)
    at java ....................
    il ya une solution ????

  12. #12
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    meme erreur lorsque je l ait mit dans la classe generator

  13. #13
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    salut,
    déplace la fonction main dans la classe Generator ça va marché.

  14. #14
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    ca na pa marché meme erreure je fé koi ??

  15. #15
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    supprime la classe exemple et n'utilise que la classe Generator. quelle commande tu utilise pour l'éxécution?

  16. #16
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    voila le fichier generator.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    package lih.rtdb.simrtdb.generator;
    import lih.rtdb.simrtdb.generator.*;
    import lih.rtdb.simrtdb.data.*;
    import java.util.*;
     
    /**
     * It is the class that permit to create arrival time using Poisson process
     * @author <a href="mailto:Majed.Abdouli@univ-lehavre.fr">Majed Abdouli</a>
     */
    public class Generator{
     
        private Random generator;
        private GlobalClock refGlobalClock;
     
        /**
         * Default Constructor
         */
        public Generator (GlobalClock refGlobalClock, Random generator){
    	this.generator = generator;
    	this.refGlobalClock = refGlobalClock;
        }
     
    public static void main(String args[])
    {
    GlobalClock C = new GlobalClock();
    Random R = new Random();
    Generator G =new Generator(C,R);
    DataBase db;
    db = G.generateDataBase(10,true,false);
    System.out.println("bdbdbdbdbdbd");
        System.out.println("Data base crée avec succee");
        }
     
        /**
         * Generate a new DataBase 
         * @param numberOfData the number of data item to generate in the database
         * @param data this value permit to specify if non real time data must be generated
         * @param realtimedata this value permit to specify if real time data must be generated
         */
        public DataBase generateDataBase (int numberOfData, 
    				      boolean data, boolean realtimedata){
    	DataBase db = new DataBase (numberOfData, generator);
    	for (int i=0; i<numberOfData; i++) {
    	    if (data && realtimedata)
    		if ((int)(Math.round(generator.nextDouble()))==0)
    		    db.add (Data.generateOne(i));
    		else
    		    db.add (RealTimeData.generateOne(i,1,generator));
    	}
    	return db;
        }
     
        }
    j utilise la commande java sous dos ( java generator)

  17. #17
    Membre averti Avatar de Rayndell
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    289
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 289
    Points : 323
    Points
    323
    Par défaut
    Euh... Question très con mais as-tu compilé ton code avant de la lancer ? (commande javac)
    "Et tu comprendras pourquoi mon nom est l'Eternel, quand sur toi s'abattra la colère du Tout-puissant."

  18. #18
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    oui bien sur je l ait compiler mais l erreur persiste encore.
    on ma dit c'est le CLASSPATH ou JAVA_HOME
    je ne sait pas quesque je met dans ces variable?????

  19. #19
    Membre averti
    Inscrit en
    Mai 2006
    Messages
    423
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 423
    Points : 303
    Points
    303
    Par défaut
    salut,
    as tu supprimé la classe exemple? quand tu exécute Generator c'est quoi l'erreur?

  20. #20
    Membre à l'essai
    Inscrit en
    Mars 2007
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 28
    Points : 11
    Points
    11
    Par défaut
    lorsque j'execute generator l'erreure est :
    Execption in thread "main" java.lang.NoClassDefFoundError : generator
    et lorsque j excute exemple c'est la meme
    Execption in thread "main" java.lang.NoClassDefFoundError : exemple
    c'est quoi la solution SVP ???

Discussions similaires

  1. Appeler une méthode dans la classe main
    Par Palsajicoco dans le forum Débuter avec Java
    Réponses: 4
    Dernier message: 04/05/2011, 11h40
  2. Réponses: 10
    Dernier message: 03/04/2011, 11h36
  3. Appeler une classe dans un autre package
    Par Nasky dans le forum Langage
    Réponses: 6
    Dernier message: 21/02/2007, 16h06
  4. Réponses: 18
    Dernier message: 06/11/2006, 21h32
  5. appel à une fonction dans la classe Action
    Par imane_bennouna dans le forum Struts 1
    Réponses: 3
    Dernier message: 07/08/2006, 11h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo