Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.nio.charset.Charset;
  6. import java.nio.file.Files;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10.  
  11. public class FileWork {
  12.  
  13. private static final String READ_MAKE = "gamintojai.txt";
  14. private static final String READ_MODEL = "modeliai.txt";
  15.  
  16. private static final String WRITE_PATH = "rezultatai.txt";
  17.  
  18. private List<String> getFileContent(String file) throws IOException {
  19. return Files.readAllLines(
  20. new File(file).toPath(),
  21. Charset.defaultCharset()
  22. );
  23. }
  24.  
  25. public List<Automobilis> gatherCars() throws IOException {
  26.  
  27. List<Automobilis> cars = new ArrayList<>();
  28. List<String> makes = getFileContent(READ_MAKE);
  29. List<String> models = getFileContent(READ_MODEL);
  30. List<String> allMakes =new ArrayList<>();
  31. int key = 0;
  32.  
  33. for (String make : makes) {
  34. String[] splitCount = make.split(" ");
  35. int makeCount = Integer.parseInt(splitCount[1]);
  36.  
  37. for (int i = 0; i < makeCount; i++) {
  38. allMakes.add(splitCount[0]);
  39. String crrMake = models.get(key);
  40. String[] splitedModel = crrMake.split("\\s+(?=\\d)");
  41. cars.add(
  42. new Automobilis(
  43. splitCount[0],
  44. splitedModel[0],
  45. Integer.parseInt(splitedModel[1]),
  46. Float.parseFloat(splitedModel[2])
  47. )
  48. );
  49. key++;
  50. }
  51.  
  52. }
  53.  
  54. return cars;
  55. }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement