BetinaUKTC

task

Jun 7th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class Task {
  6. public static void sort(ArrayList<ParkingPlace> list) {
  7. list.sort((o1, o2)
  8. -> o1.getName().compareTo(
  9. o2.getName()));
  10. }
  11.  
  12. public static void main(String[] args) {
  13. Scanner scan = new Scanner(System.in);
  14. List<ParkingPlace> list = new ArrayList<>();
  15. ParkingPlace fixedPlace = new ParkingPlace();
  16.  
  17.  
  18. //Getting all Parking Places
  19. for (int i = 1; i <= 154; i++) {
  20. ParkingPlace CurrentPlace = new ParkingPlace();
  21. System.out.println("Input number: ");
  22. String number = scan.nextLine();
  23. System.out.println("Input area: ");
  24. int area = Integer.parseInt(scan.nextLine());
  25. System.out.println("Input name");
  26. String name = scan.nextLine();
  27. System.out.println("Input Description");
  28. String description = scan.nextLine();
  29. CurrentPlace.setNumber(number);
  30. CurrentPlace.setArea(area);
  31. CurrentPlace.setName(name);
  32. CurrentPlace.setDescription(description);
  33. if (i == 74) {
  34. fixedPlace=CurrentPlace;
  35. } else {
  36. list.add(CurrentPlace);
  37. }
  38. }
  39.  
  40. list.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
  41. list.add(0,fixedPlace);
  42. for (ParkingPlace obj : list) {
  43. System.out.println(obj.getName());
  44. }
  45.  
  46.  
  47. }
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. public class ParkingPlace {
  55. String number;
  56. int area;
  57. String name;
  58. String description;
  59.  
  60. public void setNumber(String num) {
  61. this.number = num;
  62. }
  63.  
  64. public void setArea(int area) {
  65. this.area = area;
  66. }
  67.  
  68. public void setName(String name) {
  69. this.name = name;
  70. }
  71.  
  72. public void setDescription(String description) {
  73. this.description = description;
  74. }
  75.  
  76. public String getNumber() {
  77. return number;
  78. }
  79.  
  80. public int getArea() {
  81. return area;
  82. }
  83.  
  84. public String getName() {
  85. return name;
  86. }
  87.  
  88. public String getDescription() {
  89. return description;
  90. }
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment