Advertisement
Guest User

Main

a guest
Jul 14th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.LinkedList;
  6. import java.util.List;
  7.  
  8. public class Main {
  9. public static void main(String[] args) throws IOException {
  10. BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12.  
  13. List<Car> cars = new LinkedList<>();
  14.  
  15.  
  16. int n = Integer.parseInt(bf.readLine());
  17. while (n-- > 0) {
  18. String[] inline = bf.readLine().split("\\s+");
  19.  
  20. String model = inline[0];
  21. int engine = Integer.parseInt(inline[1]);
  22. int hp = Integer.parseInt(inline[2]);
  23. int cargoW = Integer.parseInt(inline[3]);
  24. String typeCargo = inline[4];
  25.  
  26. ArrayList<Tyre> tireList = new ArrayList<>();
  27. for (int i = 5; i < 12; i += 2) {
  28. double al = Double.parseDouble(inline[i]);
  29. double al2 = Double.parseDouble(inline[i + 1]);
  30. Tyre tire = new Tyre(al, al2);
  31. tireList.add(tire);
  32. }
  33. Car car = new Car(model, engine, hp, cargoW, typeCargo, tireList);
  34.  
  35. cars.add(car);
  36.  
  37.  
  38. }
  39. String com = bf.readLine();
  40. switch (com) {
  41. case "fragile":
  42.  
  43. List<String> model = new ArrayList<>();
  44. for (int i = 0; i < cars.size(); i++) {
  45. if (cars.get(i).getTypeCargo().equals("fragile")) {
  46. if (cars.get(i).getTires().get(i).getPressure() < 1) {
  47. model.add(cars.get(i).getModel());
  48. }
  49. }
  50. }
  51.  
  52. model.forEach(System.out::println);
  53. break;
  54. case "flamable":
  55. cars.forEach(e -> {
  56. if (e.getEngine() > 250) {
  57. System.out.println(String.format("%s", e.getModel()));
  58. }
  59. });
  60. break;
  61. }
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement