Guest User

Untitled

a guest
Jul 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Pu5e {
  5.  
  6. public static void main (String[] args) throws IOException {
  7.  
  8. File namnFil = Metoder2010.läsFilnamn("Vilken fil vill du läsa personer från?"); //metoden ersätter new File("filnamn.text")
  9.  
  10. File viktFil = Metoder2010.läsFilnamn("Vilken fil vill du läsa vikt från?"); //metoden ersätter new File("filnamn.text")
  11. Scanner fiVikt = new Scanner(viktFil);
  12. fiVikt = fiVikt.useDelimiter("#");
  13.  
  14. if (fiVikt.hasNext()) {
  15.  
  16.  
  17. String namnV = fiVikt.next();
  18. int viktV = fiVikt.nextInt();
  19.  
  20. Scanner fiNamn = new Scanner(namnFil);
  21. File tempFil = new File("tempfil.txt");
  22. PrintWriter fut = new PrintWriter(new BufferedWriter(new FileWriter(tempFil)));
  23.  
  24. while (fiNamn.hasNext()) {
  25. PersonU4 person = new PersonU4(fiNamn.nextLine());
  26. PersonU4 personV = new PersonU4(namnV, viktV);
  27.  
  28. if (person.heter().equalsIgnoreCase(personV.heter()))
  29. person.sättVikt(personV.geVikt());
  30.  
  31. if (fiVikt.hasNext()) {
  32. namnV = fiVikt.next();
  33. viktV = fiVikt.nextInt();
  34. }
  35. fut.println(person.geAllt());
  36. } //end of while
  37.  
  38. fiNamn.close();
  39. fut.close();
  40.  
  41. namnFil.delete();
  42. tempFil.renameTo(namnFil);
  43.  
  44. } //end of första if-satsen
  45.  
  46. fiVikt.close();
  47.  
  48. } // end of main
  49.  
  50. } // end of class
Add Comment
Please, Sign In to add comment