package [Link].
article;
/**
*
* @author TATERKIN
*/
public class Article {
//encapsulation
private long reference;
private String intitule;
private float prixHT;
private int quantite;
public long getReference() {
return reference;
}
public String getIntitule() {
return intitule;
}
//elle sera écrite une seule fois pendant
//le cycle de vie de l'objet donc le traitement sera implanté dans le
//constructeur : on ne génère pas la set de ces champs
public void setPrixHT(float prixHT) {
[Link] = prixHT;
}
public float getPrixHT() {
return prixHT;
}
public int getQuantite() {
return quantite;
}
public Article(long reference, String intitule, float prixHT, int quantite) {
[Link] = reference;
[Link] = intitule;
[Link] = prixHT;
[Link] = quantite;
}
public void approvisionner(int nbUnite){
quantite += nbUnite;
}
public boolean vendre(int nbUnite){
if(nbUnite < quantite){
quantite -= nbUnite;
return true;
}
else return false;
}
public float prixTTC(){
return (prixHT+(prixHT * 0.196f));
}
@Override
public String toString(){
return (reference + " "+ intitule + " "
+ [Link]() + " "+ quantite);
}
public boolean equals( Article a){
return (
([Link]== [Link])
&&
([Link]([Link]))
&&
([Link] == [Link])
&&
([Link]== [Link])
);
}
package [Link];
import [Link];
import [Link];
import [Link];
/*
* @author TATERKIN
*/
public class Main {
public static void main(String[] args){
/*
Article t[] = new Article[3];
Article a = new Article(0, "intitule", 0, 0);
t[0] = new Article(1, "lait", 0.5f, 100);
t[1] = new Article(1, "lait", 0.5f, 100);
t[2] = new Article(3, "pain", 4f, 300);
for(int i=0;i<[Link];i++){
[Link](t[i]);
// toString est appelé implicitement
}
[Link](t[0].equals(t[1]));
// appel à la méthode equals redéfinit ds la classe
//Article et qui a écrasé la méthode equals de la classe Object
*/
// Vector supermarche = new Vector();
Vector<Article> supermarche = new Vector<Article>();
Scanner cl = new Scanner([Link]);
int res; long ref; String intitule; float prix;int quantite;
Article a;
//[Link]([Link]());
do{
[Link]
("voulez vous ajouter un article? tapez 1 si oui 0 sinon");
res = [Link]();
if(res == 0) break;
[Link]("saissir intile + ref+ prix + quantite ");
intitule = [Link]();
ref = [Link]();
prix = [Link]();
quantite = [Link]();
a = new Article(ref, intitule, prix, quantite);
[Link](a);
}while(res != 0);
[Link]([Link]());
Iterator i = [Link]();
while([Link]()){
[Link]((Article) [Link]());
}
}
}