Problème appel de classe Java
Bonjour,
Je suis étudiant (Bachelier informatique) et je dois réaliser un projet
J'ai un problème lorsque je veux faire un appel de la classe Livre...
Je lance le programme en faisant un run,
Le Main est dans ma classe ma bilbiotheque, et je lui dis de créer un new Bibliotheque...
Le programe s'éxecute et me demande donc Combien de livre maximum voulez vous introduire dans le catalogue? jusque la tout va bien...
Mais après je lui demande d'instancier de nouveaux objet Livre mais il ne rentre pas dans la classe Livre :(
Voici ma classe Biblioteque:
Code:
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| public class Bibliotheque
{
private Livre[] catalogue;
private int nLivre = 0;
public Bibliotheque()
{
System.out.println("Combien de livre maximum voulez vous introduire dans le catalogue?");
Scanner sc=new Scanner(System.in);
int maxl = sc.nextInt();
//System.out.println(maxl);
catalogue = new Livre[maxl];
int i;
for (i=0;i<maxl;i++)
{
System.out.println("Entre boucle for");
catalogue[i] = new Livre();
}
System.out.println("Que souhaitez vous faire?");
System.out.println("[1]Ajouter un livre");
System.out.println("[2]Rechercher un titre");
System.out.println("[3]Rechercher l'ISBN d'un livre");
System.out.println("[4]Sortir");
Scanner ss=new Scanner(System.in);
int choix = ss.nextInt();
while (choix > 4 )
{
System.out.println("Le numéro encodé est incorrect");
System.out.println("Que souhaitez vous faire?");
System.out.println("[1]Ajouter un livre");
System.out.println("[2]Rechercher un titre");
System.out.println("[3]Rechercher l'ISBN d'un livre");
System.out.println("[4]Sortir");
}
switch (choix)
{
case 1: ajout();
break;
case 2: rechtitre();
break;
case 3: rechIsbn();
break;
case 4: System.exit(0) ;
break;
}
}
private void ajout()
{
System.out.println("Entre dans ajout");
catalogue[nLivre] = new Livre();
nLivre++;
System.out.println("Livre ajouté");
}
private void rechtitre()
{
System.out.println("Quel est le titre du livre recherché?");
Scanner sc=new Scanner(System.in);
String rech = sc.next();
int i;
for(i=0;i<nLivre;i++)
{
Livre l = catalogue[i];
if(l.equals(rech) )
{
System.out.println(l);
}
else System.out.println("Le livre n'est pas présent");
}
}
private void rechIsbn()
{
System.out.println("Quel est l'ISBN recherché?");
Scanner sc=new Scanner(System.in);
String isbn = sc.next();
int i;
for(i=0;i<nLivre;i++)
{
Livre l = catalogue[i];
if(l.equals(isbn))
{
System.out.println(l);
}
else System.out.println("L'ISBN n'est pas présent");
}
}
public static void main(String[] args)
{
Bibliotheque maBibli = new Bibliotheque();
}
} |
Et voici ma classe Livre
Code:
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| import java.util.*;
public class Livre
{
/**
* Variable privé qui stocke le titre du livre
*/
private String titre;
/**
* Stocke l'ISBNdu livre
*/
private String isbn;
/**
* Stocke le prixe du livre
*/
private float prix;
/**
* Stocke le nom de l'éditeur du livre
*/
private String editeurLivre;
/**
* Stocke le nom de l'auteur du livre
*/
private String auteurLivre;
/**
* Constructeur par défaut
*/
public Livre()
{
this.titre="";
this.isbn="";
this.prix=0;
this.editeurLivre="";
this.auteurLivre="";
}
/**
* Constructeur d'initialisation
*/
public void init()
{
Scanner sc=new Scanner(System.in);
System.out.print("titre du livre :");
this.titre=sc.nextLine();
System.out.print("isbn");
this.isbn=sc.next();
System.out.print("prix");
this.prix=sc.nextFloat();
sc.skip("\n");
System.out.print("éditeur");
this.editeurLivre=sc.nextLine();
System.out.print("auteur");
this.auteurLivre=sc.nextLine();
}
//***************************************************************************
// Getters
//**************************************************************************
/**
* Retourne l'auteur du livre
* @return l'auteur du livre
*/
public String getAuteurLivre()
{
return this.auteurLivre;
}
/**
* Retourne l'editeur du livre
* @return l'editeur du livre
*/
public String getEditeurLivre()
{
return this.editeurLivre;
}
/**
* Retourne l'ISBN du livre
* @return l'ISBN du livre
*/
public String getIsbn()
{
return this.isbn;
}
/**
* Retourne le prix du livre
* @return le prix du livre
*/
public float getPrix()
{
return this.prix;
}
/**
* Retourne le titre du livre
* @return le titre du livre
*/
public String getTitre()
{
return this.titre;
}
//***************************************************************************
// Setters
//***************************************************************************
/**
* Définit l'auteur du livre
* @param auteurLivre
* l' auteur du livre
*/
public void setAuteurLivre(String auteurLivre)
{
this.auteurLivre = auteurLivre;
}
/**
* Définit l'editeur du livre
* @param editeurLivre
* l'editeur du livre
*/
public void setEditeurLivre(String editeurLivre)
{
this.editeurLivre = editeurLivre;
}
/**
* Définit le prix du livre
* @param prix
* le prix du livre
*/
public void setPrix(float prix)
{
this.prix = prix;
}
} |
Je ne vois vraiment pas pourquoi il ne veut pas rentrer dans ma classe Livre depuis ma classe Biblioteque... :cry: