0% found this document useful (0 votes)
17 views4 pages

Testé

Uploaded by

Elie Masaidiyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Testé

Uploaded by

Elie Masaidiyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Voici le code pour la classe Article.

java :

```java

public class Article {

private String code;

private String libelle;

private String categorie;

private double prixUnit;

private double stock;

public Article(String code, String libelle, String categorie, double prixUnit, double stock) {

this.code = code;

this.libelle = libelle;

this.categorie = categorie;

this.prixUnit = prixUnit;

this.stock = stock;

public void acheter(double quantiteAchete) {

if (quantiteAchete <= stock) {

stock -= quantiteAchete;

} else {

System.out.println("Stock insuffisant");

public void approvisionner(double quantiteEntree) {

stock += quantiteEntree;

public String etatObjet() {


return "Code : " + code + "\n" +

"Libelle : " + libelle + "\n" +

"Categorie : " + categorie + "\n" +

"Prix unitaire : " + prixUnit + "\n" +

"Stock : " + stock;

// Getters and Setters

public String getCode() {

return code;

public void setCode(String code) {

this.code = code;

public String getLibelle() {

return libelle;

public void setLibelle(String libelle) {

this.libelle = libelle;

public String getCategorie() {

return categorie;

public void setCategorie(String categorie) {

this.categorie = categorie;

}
public double getPrixUnit() {

return prixUnit;

public void setPrixUnit(double prixUnit) {

this.prixUnit = prixUnit;

public double getStock() {

return stock;

public void setStock(double stock) {

this.stock = stock;

```

Et voici le code pour la classe TestArticle.java :

```java

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class TestArticle {

public static void main(String[] args) {

List<Article> articles = new ArrayList<>();

articles.add(new Article("001", "Article 1", "Categorie 1", 10.0, 20.0));


articles.add(new Article("002", "Article 2", "Categorie 2", 15.0, 30.0));

articles.add(new Article("003", "Article 3", "Categorie 1", 12.0, 25.0));

articles.add(new Article("004", "Article 4", "Categorie 3", 20.0, 40.0));

articles.add(new Article("005", "Article 5", "Categorie 2", 18.0, 35.0));

articles.add(new Article("006", "Article 6", "Categorie 1", 14.0, 22.0));

articles.add(new Article("007", "Article 7", "Categorie 3", 25.0, 45.0));

articles.add(new Article("008", "Article 8", "Categorie 2", 20.0, 30.0));

Scanner scanner = new Scanner(System.in);

System.out.print("Entrez une catégorie : ");

String categorie = scanner.nextLine();

You might also like