public class SansProfitException extends Exception {
public SansProfitException(String message){
super(message);
}
}
public class EntrepriseSansProfit extends Entreprise {
public EntrepriseSansProfit(String nom, String mission, int nbEmploye, long capital){
super(nom, mission, nbEmploye, capital);
}
// On indique que cette méthode peut générer des SansProfitException
public long capital() throws SansProfitException{
throw new SansProfitException("Cette entreprise ne génère pas de profit.");
}
}
public class Entreprise {
private int nbEmploye;
private long capital;
private String nom;
private String mission;
public Entreprise(){}
public Entreprise (String nom, String mission, int nbEmploye, long capital){
this.nom = nom;
this.mission = mission;
this.nbEmploye = nbEmploye;
this.capital = capital;
}
public String mission() throws MissionSecreteException{
return this.mission;
}
public long capital() throws SansProfitException{
return this.capital;
}
public void displayInfos(){
System.out.println("\n**** Informations de l'entreprise ****");
System.out.println("Nom : " + this.nom );
// Mission
try {
System.out.println( "Mission : " + this.mission() );
} catch (Exception e){
System.out.println( "Mission : [ERREUR] " + e.getMessage() );
}
System.out.println("Nombre d'employés : " + this.nbEmploye);
try {
System.out.println( "Capital : " + this.capital() );
} catch (Exception e){
System.out.println( "Capital : [ERREUR] " + e.getMessage() );
}
}
public static void displayInfos(Entreprise[] entreprisesList){
for( int i = 0; i < entreprisesList.length; i++ ){
entreprisesList[i].displayInfos();
}
}
}