Advertisement
Kotuara

Практика5.4

Dec 22nd, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Iterator;
  5.  
  6. public class Main {
  7.  
  8.  
  9.     public static class HeavyBox {
  10.         public int weight;
  11.  
  12.         public HeavyBox(int weight) {
  13.             this.weight = weight;
  14.         }
  15.  
  16.         public HeavyBox() {
  17.         }
  18.  
  19.         public boolean Weight() {
  20.             if (weight > 300) {return true;}
  21.             else return false;
  22.         }
  23.  
  24.         public void Print() {
  25.             System.out.println(weight);
  26.         }
  27.     }
  28.  
  29.         public static void Task() {
  30.             HashSet<HeavyBox> LessThan300 = new HashSet<>();
  31.             LessThan300.add(new HeavyBox(789));
  32.             LessThan300.add(new HeavyBox(237));
  33.             LessThan300.add(new HeavyBox(340));
  34.             LessThan300.add(new HeavyBox(300));
  35.             LessThan300.add(new HeavyBox(34));
  36.             HashSet<HeavyBox> MoreThan300 = new HashSet<>();
  37.             Iterator<HeavyBox> Scaler = LessThan300.iterator();
  38.             HeavyBox Box = new HeavyBox();
  39.  
  40.             while (Scaler.hasNext()) {
  41.                 Box = Scaler.next();
  42.                 if (Box.Weight())
  43.                 {
  44.                     MoreThan300.add(Box);
  45.                     Scaler.remove();
  46.                 }
  47.             }
  48.  
  49.             System.out.println("Вес <=300: ");
  50.             for (HeavyBox Box1 : LessThan300) {
  51.                 Box1.Print();
  52.             }
  53.  
  54.             System.out.println("Вес >300: ");
  55.             for (HeavyBox Box1 : MoreThan300) {
  56.                 Box1.Print();
  57.             }
  58.         }
  59.  
  60.     public static void main(String[] args) {
  61.         Task();
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement