Correspondance entre 2 classes
Bonjour
je realise en ce moment une application java qui doit être capable des gérer des films.
j'ai donc créé une classe Acteur :
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
|
public class Acteur {
String nom;
String prenom;
public Acteur (String _nom, String _prenom){
nom=_nom;
prenom=_prenom;
}
public void afficher (){
System.out.println(nom + " " + prenom);
}
} |
une classe Film :
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
|
import java.util.*;
public class Film {
private String titre;
public String resume;
private Vector acteur = new Vector();
private String genre;
private int nbdispo;
static String genre1="Action";
static String genre2="Aventure";
static String genre3="Fantastique";
static String genre4="Guerre";
static String genre5="Documentaire";
static String genre6="Comedie";
public Film (String _titre){
titre=_titre;
}
public void setGenre (String _genre) throws GenreException{
if (!((_genre.equals(genre1))||(_genre.equals(genre2))||(_genre$
throw new GenreException ("Genre indisponible");
}
genre=_genre;
}
public void ajout (int i){
nbdispo=nbdispo+i;
}
public void retire (int i) throws DVDindispo{
if (i>nbdispo){
throw new DVDindispo("La quantitee a retirer est superi$ }
nbdispo=nbdispo-i;
}
public void addacteur (Acteur _acteur){
acteur.add(_acteur);
}
public void getDescriptif () {
Iterator it = acteur.iterator();
System.out.println("Titre : " + titre);
System.out.println("Genre : " + genre);
System.out.println("Nb DVD disponible : " + nbdispo);
System.out.println("Acteurs : ");
while (it.hasNext()){
Acteur a = (Acteur)it.next();
a.afficher();
}
System.out.println(resume);
System.out.println();
} |
et une classe StockFactory (qui est le main) :
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
|
class StockFactory {
public static void main (String [] args){
Acteur act1 = new Acteur ("Stallone", "Sylvester");
Acteur act2 = new Acteur ("De Fun�s", "Louis");
Acteur act3 = new Acteur ("Galabru", "Michel");
Acteur act4 = new Acteur ("De Niro", "Robert");
Acteur act5 = new Acteur ("Pacino", "Al");
Acteur act6 = new Acteur ("Dujardin", "Jean");
Acteur act7 = new Acteur ("Di caprio", "Leonardo");
Acteur act8 = new Acteur ("Samuel", "Jackson");
Acteur act9 = new Acteur ("Washington", "Denzel");
Acteur act10 = new Acteur ("Chaplin", "Charlie");
Film film1 = new Film ("Heat");
Film film2 = new Film ("Training Day");
Film film3 = new Film ("Les Gendarmes de St Tropez");
film1.addacteur(act4);
film1.addacteur(act5);
film2.addacteur(act9);
film3.addacteur(act2);
film3.addacteur(act3);
try {
film1.setGenre("Action");
}catch (GenreException e){
System.out.println(e);
}
try {
film2.setGenre("Action");
}catch (GenreException e){
System.out.println(e);
}
try {
film3.setGenre("Comedie");
}catch (GenreException e){
System.out.println(e);
}
film1.resume="Film policier";
film2.resume="Film policier";
film3.resume="Les gendarmes sont en vacances a St-Tropez, il fait beau $
film1.ajout(4);
film2.ajout(8);
film3.ajout(2);
film1.getDescriptif();
film2.getDescriptif();
film3.getDescriptif();
}
} |
et pour finir une classe Stock(qui n'est pas encore finie) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
public class Stock {
private static Vector listeDesFilms = new Vector();
public void Stock (){
} |
Enfet je voudrais que tout film nouvellement créé soit ajouté à la propriété listeDesFilms de la classe Stock!
Quelqu'un aurait une idée svp? merci