Correction Examen principal P.O.
Exercice 1 :
class RemplirTableau
{
private int []tab=new int[10];
public tableau() throws EntierException
{
for(int i=0; i<10;i++)
{
tab[i]=(int)([Link]()*100);
if(tab[i]>=10 && tab[i]<=20) throw new EntierException();
}
}
}
class EntierException extends Exception
{
void afficheErreur()
{
[Link]("Erreur");
}
}
public class Exercice3Examen {
public static void main (String[] args) {
try{
RemplirTableau t=new RemplirTableau();
} catch(EntierException e)
{
[Link]();
}
}
}
Problème
class Article //implements Vendable_Kilo,Vendable_Piece,Vendable_Solde
{
public String Nom;
private double prixAchat;
public double prixVente;
public String Fournisseur;
public double stock;
public double getPrixAchat() {
return prixAchat;
}
public void setPrixAchat(double prixAchat) {
[Link] = prixAchat;
}
public Article(String n, double pA, double pV, String f, double s) {
Nom = n;
prixAchat = pA;
prixVente = pV;
Fournisseur = f;
stock = s;
}
public double Remplir_stock(double q) {
stock = stock+q;
return (prixVente - prixAchat) / prixAchat;
}
public void Info_Produit() {
[Link]("Nom du produit:" + Nom);
[Link]("Prix d'achat: " + prixAchat);
[Link]("Prix de vente: " + prixVente);
[Link]("Fournisseur: " + Fournisseur);
[Link]("Stock: " + stock);
}
//partie non notée
public double Revenu(double d) {
// TODO Auto-generated method stub
return 0;
}
//partie non notée
public double Lancer_Solde(double i) {
// TODO Auto-generated method stub
return 0;
}
}
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);
}
class AE extends Article implements Vendable_Piece, Vendable_Solde
{
private int garantie;
// 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();
[Link]("La garantie est "+garantie);
}
public void Taxe_PA() {
double t =[Link]()-((18*10)/100);
[Link]("le prix d'achat sans taxe est "+t);
}
// implementation de l'interface vendablePiece
public double Revenu(double qte) {
if (qte<stock) {
stock = stock - qte;
return qte * prixVente;
}
else {
[Link]("Stock insuffisant.");
return 0;
}
}
// implementation de l'interface solde
public double Lancer_Solde(double Pourcentage) {
prixVente = prixVente - prixVente * Pourcentage/100;
return prixVente;
}
public double Terminer_Solde(double Pourcentage) {
prixVente = prixVente + prixVente * Pourcentage/100;
return prixVente;
}
}
class AA extends Article implements Vendable_Kilo
{
public String date_exp;
// constructeur n'est pas noté
public AA(String n,double pA, double pV, String f, int s, String d)
{
super(n,pA,pV,f,s);
date_exp=d;
}
// 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();
[Link]("La date d'expiration est "+date_exp);
}
// implementation de l'interface vendableKilo
public double Revenu(double qte) {
if (qte<stock) {
stock = stock - qte;
return qte * prixVente;
}
else {
[Link]("Stock insuffisant.");
return 0;
}
}
}
// 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<[Link];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);
//test : affichage du contenu du tableau
for(int i=0;i<[Link];i++)
depot[i].Info_Produit();
r1= depot[0].Revenu(3.0);
[Link]("la valeur est"+r1);
double r2= depot[1].Revenu(15.0);
[Link]("la valeur est"+r2);
double r3=depot[2].Revenu(70.0);
[Link]("la valeur est"+r3);
double r4=depot[3].Revenu(30.0);
[Link]("la valeur est"+r4);
[Link]("le solde est "+depot[0].Lancer_Solde(30));
}}