Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Task {
- public static void sort(ArrayList<ParkingPlace> list) {
- list.sort((o1, o2)
- -> o1.getName().compareTo(
- o2.getName()));
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- List<ParkingPlace> list = new ArrayList<>();
- ParkingPlace fixedPlace = new ParkingPlace();
- //Getting all Parking Places
- for (int i = 1; i <= 154; i++) {
- ParkingPlace CurrentPlace = new ParkingPlace();
- System.out.println("Input number: ");
- String number = scan.nextLine();
- System.out.println("Input area: ");
- int area = Integer.parseInt(scan.nextLine());
- System.out.println("Input name");
- String name = scan.nextLine();
- System.out.println("Input Description");
- String description = scan.nextLine();
- CurrentPlace.setNumber(number);
- CurrentPlace.setArea(area);
- CurrentPlace.setName(name);
- CurrentPlace.setDescription(description);
- if (i == 74) {
- fixedPlace=CurrentPlace;
- } else {
- list.add(CurrentPlace);
- }
- }
- list.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
- list.add(0,fixedPlace);
- for (ParkingPlace obj : list) {
- System.out.println(obj.getName());
- }
- }
- }
- public class ParkingPlace {
- String number;
- int area;
- String name;
- String description;
- public void setNumber(String num) {
- this.number = num;
- }
- public void setArea(int area) {
- this.area = area;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public String getNumber() {
- return number;
- }
- public int getArea() {
- return area;
- }
- public String getName() {
- return name;
- }
- public String getDescription() {
- return description;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment