Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Evaluations {
- Hashtable<String, Hashtable<String,Double>> mEvaluations = new Hashtable<String, Hashtable<String,Double>>();
- public Evaluations(String nomdufichier) throws IOException {
- litFichier(new File(nomdufichier));
- }
- public void litFichier(File fichier) throws IOException {
- BufferedReader br = new BufferedReader(new FileReader(fichier));
- try {
- String line;
- while((line = br.readLine())!= null) {
- String[] vals = line.split(" ");
- if(vals.length == 0) continue;
- String utilisateurs = vals[0];
- if(mEvaluations.contains(utilisateurs)) {
- System.err.println("La clef "+utilisateurs+" est utilisée plus d'une fois.");
- continue;
- }
- Hashtable<String,Double> notes = new Hashtable<String,Double>();
- for(int k = 1; k< vals.length;++k) {
- String[] n = vals[k].split(":");
- if(n.length != 2) {
- System.err.println("fichier mal formé? "+n[k]);
- continue;
- }
- Double d = new Double(n[1]);
- notes.put(n[0],d);
- }
- mEvaluations.put(utilisateurs, notes);
- }
- } finally {
- br.close();
- }
- }
- public Set<String> utilisateurs() {
- return mEvaluations.keySet();
- }
- public Set<Map.Entry<String,Double>> evaluations(String nom) {
- return mEvaluations.get(nom).entrySet();
- }
- public static void main(String[] args) throws IOException {
- Evaluations e = new Evaluations(args[0]);
- for (String nom: e.utilisateurs()) {
- System.out.println("Utilisateur "+nom);
- for( Map.Entry<String,Double> me : e.evaluations(nom)) {
- System.out.println("\taccorde une note de "+me.getValue()+" à l'article "+me.getKey());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement