fork download
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. class Ward {
  5. private int capacity; // количество мест
  6. private String doctorSurname;
  7. private boolean availableBeds; // наличие свободных коек
  8.  
  9. public Ward(int capacity, String doctorSurname, boolean availableBeds) {
  10. this.capacity = capacity;
  11. this.doctorSurname = doctorSurname;
  12. this.availableBeds = availableBeds;
  13. }
  14.  
  15. public int getCapacity() {
  16. return capacity;
  17. }
  18.  
  19. public String getDoctorSurname() {
  20. return doctorSurname;
  21. }
  22.  
  23. public boolean hasAvailableBeds() {
  24. return availableBeds;
  25. }
  26. }
  27.  
  28. public class Main {
  29. public static void main(String[] args) {
  30. // Создаем список палат и фамилии врачей.
  31. List<Ward> wards = new ArrayList<>();
  32. wards.add(new Ward(10, "Иванов", true));
  33. wards.add(new Ward(15, "Петров", false));
  34. wards.add(new Ward(12, "Сидоров", true));
  35. wards.add(new Ward(8, "Козлов", true));
  36.  
  37. int totalCapacity = 0;
  38. int availableWards = 0;
  39.  
  40. // Проходим по всем палатам для подсчета общего количества мест и количества палат с доступными койками
  41. for (Ward ward : wards) {
  42. totalCapacity += ward.getCapacity();
  43. if (ward.hasAvailableBeds()) {
  44. availableWards++;
  45. }
  46. }
  47.  
  48. System.out.println("Общее количество мест: " + totalCapacity);
  49. System.out.println("Количество палат с доступными койками: " + availableWards);
  50. }
  51. }
  52.  
Success #stdin #stdout 0.11s 53636KB
stdin
Standard input is empty
stdout
Общее количество мест: 45
Количество палат с доступными койками: 3