Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. private static ArrayList<Bil> filleser(String filnavn){
  2. String linje = "";
  3. ArrayList<Bil> bilene = new ArrayList<Bil>();
  4.  
  5. try{
  6. BufferedReader lesFil = new BufferedReader(new FileReader(filnavn));
  7.  
  8. while((linje = lesFil.readLine()) != null){
  9. String[] split = linje.split(" ");
  10.  
  11. String type = split[0];
  12. String ord = split[1];
  13. double ord2 = 0;
  14. double ord3 = 0;
  15. int ord4 = 0;
  16.  
  17. if(split.length > 2){
  18. ord2 = Double.parseDouble(split[2]);
  19. } if(split.length > 3){
  20. ord3 = Double.parseDouble(split[3]);
  21. } if (split.length > 4){
  22. ord4 = Integer.parseInt(split[4]);
  23. }
  24. if(type.equals("BIL")){
  25. Bil bil = new Bil(split[0], ord);
  26. bilene.add(bil);
  27. } else if (type.equals("EL")){
  28. Elbiler bil = new Elbiler(type, ord, ord2);
  29. bilene.add(bil);
  30. } else if (type.equals("FOSSIL")){
  31. Fossilbiler bil = new Fossilbiler(type, ord, ord2);
  32. bilene.add(bil);
  33. } else if (type.equals("LASTEBIL")){
  34. Lastebiler bil = new Lastebiler(type, ord, ord3, ord2);
  35. bilene.add(bil);
  36. } else if (type.equals("PERSONBIL")){
  37. Personbiler bil = new Personbiler(type, ord, ord2, ord4);
  38. bilene.add(bil);
  39. } else {
  40. System.out.println("Error, ikke gyldig bil.");
  41. }
  42. }
  43. lesFil.close();
  44. }
  45. catch(Exception e){
  46. System.out.println("Error: Noe galt med fil eller no'.");
  47. System.exit(0);
  48. }
  49. return bilene;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement