here is my code did you understand it say just yes or no : import java.util.*;
import java.util.stream.Collectors;

public class pop {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        Sommet nodeA = new Sommet("A");
        Sommet nodeB = new Sommet("B");
        Sommet nodeC = new Sommet("C");
        Sommet nodeD = new Sommet("D");

        Arete areteAB = new Arete(nodeA, nodeB, 2);
        Arete areteAC = new Arete(nodeA, nodeC, 3);
        Arete areteBD = new Arete(nodeB, nodeD, 8);
        Arete areteCD = new Arete(nodeC, nodeD, 6);

        nodeA.addArete(areteAB);
        nodeA.addArete(areteAC);
        nodeB.addArete(areteBD);
        nodeC.addArete(areteCD);

        ArrayList<Sommet> sommets = new ArrayList<>(Arrays.asList(nodeA, nodeB, nodeC, nodeD));
        ArrayList<Arete> aretes = new ArrayList<>(Arrays.asList(areteAB, areteAC, areteBD, areteCD));

        Graph graph = new Graph(sommets, aretes);
        System.out.println("Voici le graphe : ");
        graph.displayGraphInfo();

        System.out.println("Choisissez le sommet de départ (par ex. A):");
        Sommet depart = findSommetByName(sommets, scan.nextLine());

        System.out.println("Choisissez le sommet d’arrivée (par ex. D):");
        Sommet cible = findSommetByName(sommets, scan.nextLine());

        scan.close();

        if (depart != null && cible != null) {
            runDijkstra(graph, depart, cible);
        } else {
            System.out.println("L’un des sommets spécifiés n’existe pas.");
        }
    }

    private static Sommet findSommetByName(ArrayList<Sommet> sommets, String nom) {
        for (Sommet sommet : sommets) {
            if (sommet.getNom().equalsIgnoreCase(nom)) {
                return sommet;
            }
        }
        System.out.println("Le sommet " + nom + " n’existe pas dans le graphe");
        return null;
    }

    public static void runDijkstra(Graph graph, Sommet depart, Sommet cible) {
        final Map<Sommet, Double> distances = new HashMap<>();
        final Map<Sommet, Sommet> predecessors = new HashMap<>();
        Set<Sommet> unsettledNodes = new HashSet<>(graph.getSommets());
        Set<Sommet> settledNodes = new HashSet<>();

        for (Sommet sommet : graph.getSommets()) {
            distances.put(sommet, Double.POSITIVE_INFINITY);
        }
        distances.put(depart, 0.0);

        while (!unsettledNodes.isEmpty()) {
            Sommet current = getLowestDistanceNode(unsettledNodes, distances);
            unsettledNodes.remove(current);
            settledNodes.add(current);

            for (Arete arete : current.getAretes()) {
                Sommet adjacent = arete.getDestination();
                if (settledNodes.contains(adjacent)) continue;
                double edgeWeight = arete.getPoids();
                if (distances.get(current) + edgeWeight < distances.get(adjacent)) {
                    distances.put(adjacent, distances.get(current) + edgeWeight);
                    predecessors.put(adjacent, current);
                }
            }
        }

        printShortestPath(cible, predecessors, distances);
    }

    private static Sommet getLowestDistanceNode(Set<Sommet> unsettledNodes, Map<Sommet, Double> distances) {
        Sommet lowestDistanceNode = null;
        double lowestDistance = Double.POSITIVE_INFINITY;
        for (Sommet node : unsettledNodes) {
            double nodeDistance = distances.get(node);
            if (nodeDistance < lowestDistance) {
                lowestDistance = nodeDistance;
                lowestDistanceNode = node;
            }
        }
        return lowestDistanceNode;
    }

    private static void printShortestPath(Sommet target, Map<Sommet, Sommet> predecessors, Map<Sommet, Double> distances) {
        LinkedList<Sommet> path = new LinkedList<>();
        Sommet current = target;

        if (predecessors.get(current) == null && !current.equals(target)) {
            System.out.println("Aucun chemin trouvé de " + target.getNom());
            return;
        }
        path.add(current);
        while (predecessors.containsKey(current)) {
            current = predecessors.get(current);
            path.addFirst(current);
        }
        System.out.println("Chemin le plus court : " + pathToString(path) + ", Distance totale : " + distances.get(target));
    }

    private static String pathToString(LinkedList<Sommet> path) {
        return path.stream().map(Sommet::getNom).collect(Collectors.joining(" -> "));
    }
}

class Graph {
    private ArrayList<Sommet> sommets;
    private ArrayList<Arete> aretes;

    Graph(ArrayList<Sommet> sommets, ArrayList<Arete> aretes) {
        this.sommets = sommets;
        this.aretes = aretes;
    }

    public ArrayList<Sommet> getSommets() {
        return sommets;
    }

    public void displayGraphInfo() {
        System.out.println("-----------------------------");
        System.out.println("Nombre de sommets: " + sommets.size());
        System.out.println("Sommets:");
        for (Sommet sommet : sommets) {
            System.out.println("- " + sommet.getNom());
        }
        System.out.println("Arêtes:");
        for (Arete arete : aretes) {
            System.out.println("- De: " + arete.getSource().getNom() + " à " + arete.getDestination().getNom() + ", poids: " + arete.getPoids());
        }
        System.out.println("-----------------------------");
    }
}

class Sommet {
    private String nom;
    private ArrayList<Arete> aretes;

    Sommet(String nom) {
        this.nom = nom;
        this.aretes = new ArrayList<>();
    }

    public String getNom() {
        return nom;
    }

    public ArrayList<Arete> getAretes() {
        return aretes;
    }

    public void addArete(Arete arete) {
        aretes.add(arete);
    }
}

class Arete {
    private Sommet source;
    private Sommet destination;
    private int poids;

    Arete(Sommet source, Sommet destination, int poids) {
        this.source = source;
        this.destination = destination;
        this.poids = poids;
    }

    public Sommet getSource() {
        return source;
    }

    public Sommet getDestination() {
        return destination;
    }

    public int getPoids() {
        return poids;
    }
}