1)
import [Link].*;
public class GestionStock {
private Map<String, Integer> stock;
public GestionStock() {
stock = new HashMap<>();
// Ajouter ou cumuler un article
public void ajouterArticle(String nom, int quantite) {
[Link](nom, [Link](nom, 0) + quantite);
// Extraire les articles en rupture (<5)
public List<String> extraireRupture() {
List<String> rupture = new ArrayList<>();
for ([Link]<String, Integer> entry : [Link]()) {
if ([Link]() < 5) {
[Link]([Link]());
}
return rupture;
// Afficher stock trié alphabétiquement
public void afficherStockTrie() {
List<String> articles = new ArrayList<>([Link]());
[Link](articles);
for (String article : articles) {
[Link](article + " : " + [Link](article));
// Test rapide
public static void main(String[] args) {
GestionStock gs = new GestionStock();
[Link]("Stylo", 10);
[Link]("Cahier", 3);
[Link]("Crayon", 2);
[Link]("Stylo", 5);
[Link]("Stock trié :");
[Link]();
[Link]("\nArticles en rupture :");
[Link]([Link]());
2) import [Link].*;
public class AnalyseurTexte {
// Comptage des mots
public static Map<String, Integer> analyserTexte(List<String> mots) {
Map<String, Integer> frequence = new HashMap<>();
for (String mot : mots) {
[Link](mot, [Link](mot, 0) + 1);
return frequence;
// Afficher les mots fréquents (>3)
public static void afficherMotsFrequents(Map<String, Integer> map) {
for ([Link]<String, Integer> entry : [Link]()) {
if ([Link]() > 3) {
[Link]([Link]() + " : " + [Link]());
}
// Mot le plus utilisé
public static String motLePlusUtilise(Map<String, Integer> map) {
String motMax = null;
int max = 0;
for ([Link]<String, Integer> entry : [Link]()) {
if ([Link]() > max) {
max = [Link]();
motMax = [Link]();
return motMax;
// Test
public static void main(String[] args) {
List<String> mots = [Link](
"java", "code", "java", "tp", "java",
"code", "java", "map", "code", "code"
);
Map<String, Integer> resultat = analyserTexte(mots);
[Link]("Fréquence des mots :");
[Link](resultat);
[Link]("\nMots fréquents (>3) :");
afficherMotsFrequents(resultat);
[Link]("\nMot le plus utilisé :");
[Link](motLePlusUtilise(resultat));
_____________________________
3) class Coureur1 extends Thread {
@Override
public void run() {
int[] distances = {10, 20, 50};
for (int d : distances) {
[Link]("Coureur 1 : " + d + "m");
try {
[Link]((int)([Link]() * 1000));
} catch (InterruptedException e) {
[Link]();
[Link]("Coureur 1 a passé le témoin !");
class Coureur2 extends Thread {
@Override
public void run() {
int[] distances = {60, 80, 100};
for (int d : distances) {
[Link]("Coureur 2 : " + d + "m");
try {
[Link]((int)([Link]() * 1000));
} catch (InterruptedException e) {
[Link]();
[Link]("Course terminée !");
}
public class CourseRelais {
public static void main(String[] args) {
Coureur1 c1 = new Coureur1();
Coureur2 c2 = new Coureur2();
[Link]();
try {
// Synchronisation : attendre la fin du coureur 1
[Link]();
} catch (InterruptedException e) {
[Link]();
// Démarrer le coureur 2 seulement après
[Link]();