import java.util.Arrays;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
        Room room1 = new Room(1, "A101", 2);
        room1.setComfortType("Стандарт");
        room1.setPrice(3000.0);

        Room room2 = new Room(2, "B202", 64);
        room2.setComfortType("Кладовка");
        room2.setPrice(15000.0);


        Room room3 = new Room(2, "C303", 4);
        room3.setComfortType("Люкс");
        room3.setPrice(7000.0);


        GroupRoom group = new GroupRoom(new Room[] {room1, room2, room3});

        System.out.println(group);

        group.sortRoomsByPrice();

        System.out.println("После сортировки по цене:");
        System.out.println(group);
    }
}

class Room {
    private int id;
    private String codeNumbers;
    private int numberPeople;
    private String comfortType;
    private double price;

    public Room(int id, String codeNumbers, int numberPeople) {
        this.id = id;
        this.codeNumbers = codeNumbers;
        this.numberPeople = numberPeople;
    }

    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    public String getCodeNumbers() { return codeNumbers; }
    public void setCodeNumbers(String codeNumbers) { this.codeNumbers = codeNumbers; }

    public int getNumberPeople() { return numberPeople; }
    public void setNumberPeople(int numberPeople) { this.numberPeople = numberPeople; }

    public String getComfortType() { return comfortType; }
    public void setComfortType(String comfortType) { this.comfortType = comfortType; }

    public double getPrice() { return price; }
    public void setPrice(double price) { this.price = price; }

    @Override
    public String toString() {
        return String.format("Room{id=%d, codeNumbers='%s', numberPeople=%d, comfortType='%s', price=%.2f}",
                id, codeNumbers, numberPeople,
                comfortType != null ? comfortType : "не задан", price);
    }
}

class GroupRoom {
    static private int uniqueNumberCounter = 0;
    private final int uniqueNumber;
    private Room[] rooms;

    public GroupRoom() {
        this.uniqueNumber = uniqueNumberCounter;
        uniqueNumberCounter++;
        this.rooms = new Room[0];
    }

    public GroupRoom(Room[] rooms) {
        this.uniqueNumber = uniqueNumberCounter;
        uniqueNumberCounter++;
        this.rooms = rooms != null ? rooms : new Room[0];
    }

    public Room[] getRooms() {
        return rooms;
    }

    public void setRooms(Room[] rooms) {
        this.rooms = rooms;
    }

    public Room getRoom(int index) {
        if (index >= 0 && index < rooms.length) {
            return rooms[index];
        }
        return null;
    }

    public void setRoom(int index, Room room) {
        if (index >= 0 && index < rooms.length) {
            rooms[index] = room;
        }
    }

    public void addRoom(Room room) {
        Room[] newRooms = Arrays.copyOf(rooms, rooms.length + 1);
        newRooms[newRooms.length - 1] = room;
        rooms = newRooms;
    }

    public void removeRoomById(int id) {
        rooms = Arrays.stream(rooms)
                .filter(r -> r.getId() != id)
                .toArray(Room[]::new);
    }

    public void sortRoomsByPrice() {
        Arrays.sort(rooms, Comparator.comparingDouble(Room::getPrice));
    }

    @Override
    public String toString() {
        String result = "GroupRoom uniqueNumber = " + uniqueNumber + "\nRooms:\n";
        for (int i = 0; i < rooms.length; i++) {
            result += rooms[i].toString() + "\n";
        }
        return result;
    }
}
