package labo3;
import java.util.*;
/**
*
* @author DequesneAllan
*/
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();
catalogue = new Livre[maxl];
int choix = 0;
while (choix != 4)
{
System.out.println("Que souhaitez vous faire?");
System.out.println("[1]Ajouter un livre");
System.out.println("[2]Rechercher des information sur un livre à partir de son titre");
System.out.println("[3]Rechercher des information sur un livre à partir de son ISBN");
System.out.println("[4]Sortir");
Scanner ss=new Scanner(System.in);
choix = ss.nextInt();
switch (choix)
{
case 1: ajout(maxl);
break;
case 2: rechtitre();
break;
case 3: rechIsbn();
break;
case 4: System.exit(0) ;
break;
}
while ((choix !=4)&&(choix!=3)&&(choix!=2)&&(choix!= 1))
{
System.out.println("La valeur que vous venez de rentrer est incorrect");
System.out.println("Que souhaitez vous faire?");
System.out.println("[1]Ajouter un livre");
System.out.println("[2]Rechercher des information sur un livre à partir de son titre");
System.out.println("[3]Rechercher des information sur un livre à partir de son ISBN");
System.out.println("[4]Sortir");
Scanner sl=new Scanner(System.in);
choix = sl.nextInt();
switch (choix)
{
case 1: ajout(maxl);
break;
case 2: rechtitre();
break;
case 3: rechIsbn();
break;
case 4: System.exit(0) ;
break;
}
}
}
}
private void ajout(int maxl)
{
if (nLivre < maxl)
{
catalogue[nLivre] = new Livre();
nLivre++;
}
else
{
System.out.println("[ATTENTION] LE NOMBRE DE LIVRE MAXIMUM DANS LE CATALOGUE EST ATTEIND");
System.out.println("VOUS NE POUVEZ PLUS AJOUTER DE LIVRE DANS LE CATALOGUE");
int choix = 0;
while (choix != 4)
{
System.out.println("Que souhaitez vous faire?");
System.out.println("[1]Rechercher des information sur un livre à partir de son titre");
System.out.println("[2]Rechercher des information sur un livre à partir de son ISBN");
System.out.println("[3]Sortir");
Scanner ss=new Scanner(System.in);
choix = ss.nextInt();
switch (choix)
{
case 1: rechtitre();
break;
case 2: rechIsbn();
break;
case 3: System.exit(0) ;
break;
}
while ((choix !=4)&&(choix!=3)&&(choix!=2)&&(choix!= 1))
{
System.out.println("LA VALEUR QUE VOUS VENEZ DE RENTRER EST INCORRECT");
System.out.println("Que souhaitez vous faire?");
System.out.println("[1]Ajouter un livre");
System.out.println("[2]Rechercher des information sur un livre à partir de son titre");
System.out.println("[3]Rechercher des information sur un livre à partir de son ISBN");
System.out.println("[4]Sortir");
Scanner sl=new Scanner(System.in);
choix = sl.nextInt();
switch (choix)
{
case 1: ajout(maxl);
break;
case 2: rechtitre();
break;
case 3: rechIsbn();
break;
case 4: System.exit(0) ;
break;
}
}
}
}
}
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=0;
for(i=0;i<nLivre;i++)
{
Livre l = catalogue[i];
if(l.getTitre().equals(rech) )
{
System.out.println("Le livre: " +l.getTitre()+" est présent dans la catalogue");
System.out.println("ISBN: " +l.getIsbn());
System.out.println("Prix: " +l.getPrix());
System.out.println("Auteur " +l.getAuteurLivre());
System.out.println("Editeur " +l.getEditeurLivre());
}
else
if ((l.getTitre().equalsIgnoreCase(rech)) && (i == nLivre-1))
System.out.println("LE LIVRE RECHERCHÉ N'EST PAS DANS LE CATALOGUE");
}
}
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.getIsbn().equals(isbn))
{
System.out.println("L'ISBN: "+l.getIsbn()+" est présent dans le catalogue");
System.out.println("Titre: " +l.getTitre());
System.out.println("Prix: " +l.getPrix());
System.out.println("Auteur " +l.getAuteurLivre());
System.out.println("Editeur " +l.getEditeurLivre());
}
else
if ((l.getTitre().equalsIgnoreCase(isbn))&&(i == nLivre-1))
System.out.println("LE LIVRE RECHERCHÉ N'EST PAS DANS LE CATALOGUE");
}
}
public static void main(String[] args)
{
Bibliotheque maBibli = new Bibliotheque();
}
}
Partager