Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.HashSet;
- import java.util.Iterator;
- public class Main {
- public static class HeavyBox {
- public int weight;
- public HeavyBox(int weight) {
- this.weight = weight;
- }
- public HeavyBox() {
- }
- public boolean Weight() {
- if (weight > 300) {return true;}
- else return false;
- }
- public void Print() {
- System.out.println(weight);
- }
- }
- public static void Task() {
- HashSet<HeavyBox> LessThan300 = new HashSet<>();
- LessThan300.add(new HeavyBox(789));
- LessThan300.add(new HeavyBox(237));
- LessThan300.add(new HeavyBox(340));
- LessThan300.add(new HeavyBox(300));
- LessThan300.add(new HeavyBox(34));
- HashSet<HeavyBox> MoreThan300 = new HashSet<>();
- Iterator<HeavyBox> Scaler = LessThan300.iterator();
- HeavyBox Box = new HeavyBox();
- while (Scaler.hasNext()) {
- Box = Scaler.next();
- if (Box.Weight())
- {
- MoreThan300.add(Box);
- Scaler.remove();
- }
- }
- System.out.println("Вес <=300: ");
- for (HeavyBox Box1 : LessThan300) {
- Box1.Print();
- }
- System.out.println("Вес >300: ");
- for (HeavyBox Box1 : MoreThan300) {
- Box1.Print();
- }
- }
- public static void main(String[] args) {
- Task();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement