Advertisement
Kotuara

Практика5.1

Dec 22nd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5.  
  6. public class Main {
  7.  
  8.     public static class HeavyBox
  9.     {
  10.         public String id;
  11.         public int weight;
  12.  
  13.         public HeavyBox(String id, int weight)
  14.         {
  15.             this.id = id;
  16.             this.weight = weight;
  17.         }
  18.  
  19.         public void Print()
  20.         {
  21.             System.out.println(id);
  22.             System.out.println(weight + "\n");
  23.         }
  24.     }
  25.  
  26.     public static void main(String[] args)
  27.     {
  28.         HeavyBox Box1 = new HeavyBox("Тяжелый", 789);
  29.         HeavyBox Box2 = new HeavyBox("Средний", 237);
  30.         HeavyBox Box3 = new HeavyBox("Легкий", 34);
  31.         ArrayList<HeavyBox> Warehouse = new ArrayList<>(Arrays.asList(Box1, Box2, Box3));
  32.  
  33.         for (HeavyBox Box : Warehouse) {
  34.             Box.Print();
  35.         }
  36.  
  37.         Box1.weight=1;
  38.         System.out.println("Вес первого ящика: " +Box1.weight);
  39.         Warehouse.remove(2);
  40.         Warehouse.clear();
  41.         if (Warehouse.isEmpty()) {System.out.println("Все ящики удалены");}
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement