Académique Documents
Professionnel Documents
Culture Documents
Exercice 1 :
class RemplirTableau
{
private int []tab=new int[10];
public tableau() throws EntierException
{
for(int i=0; i<10;i++)
{
tab[i]=(int)(Math.random()*100);
if(tab[i]>=10 && tab[i]<=20) throw new EntierException();
}
}
}
class EntierException extends Exception
{
void afficheErreur()
{
System.out.println("Erreur");
}
}
public class Exercice3Examen {
Problème
interface Vendable_Kilo
{
// cette méthode retourne le revenu de la vente
public double Revenu(double qte);
}
interface Vendable_Piece
{
// cette méthode retourne le revenu de la vente
public double Revenu(double qte);
}
interface Vendable_Solde
{
public double Lancer_Solde(double Pourcentage);
public double Terminer_Solde(double Pourcentage);
}
// constructeur
public AE(String n,double pA, double pV, String f, double s, int g)
{
super(n,pA,pV,f,s);
garantie= g;
}
// nouvelles méthodes
// public double RemplirStock(int qte) {
// stock = stock + qte;
// return prixAchat * qte;
//}
// méthode surécrite
public void Info_Produit() {
super.Info_Produit();
System.out.println("La garantie est "+garantie);
}
// nouvelles méthodes
//public double RemplirStock(double qte) {
// stock = stock + qte;
//return prixAchat * qte;
//}
// méthode surécrite
public void Info_Produit() {
super.Info_Produit();
System.out.println("La date d'expiration est "+date_exp);
}
// programme principal
public class probleme {
public static void main (String[] args) {
Article [] depot =new Article [4];
double r1;
// les produits a vendre
depot[0] = new AE("TéléLCD",1000,1300,"SAMSUNG",10,24);
depot[1] = new AA("tomate",1400,1600,"SICAM",500,"12/11/2014");
depot[2] = new AE("four",100,140,"SOTACER",20,12);
depot[3] = new AA("Jus",1500,1900,"GENERAL
ALIMENTAIRE",200,"03/06/2013");
for(int i=0;i<depot.length;i++)
depot[i].Info_Produit();
depot[0].Remplir_stock(-3);
depot[1].Remplir_stock(-15);
depot[2].Remplir_stock(-70);
depot[3].Remplir_stock(-30);
r1= depot[0].Revenu(3.0);
System.out.println("la valeur est"+r1);
double r2= depot[1].Revenu(15.0);
System.out.println("la valeur est"+r2);
double r3=depot[2].Revenu(70.0);
System.out.println("la valeur est"+r3);
double r4=depot[3].Revenu(30.0);
System.out.println("la valeur est"+r4);