package com.javarush.task.task08.task0819;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/*
Set из котов
*/
public class Solution {
public static void main(String[] args) {
Set<Cat> cats = createCats();
//напишите тут ваш код. step 3 - пункт 3
cats.remove(cats.iterator().next());
printCats(cats);
}
public static Set<Cat> createCats() {
//напишите тут ваш код. step 2 - пунк
HashSet<Cat> murCat = new HashSet<>();
murCat.add(new Cat("mur",3,5));
murCat.add(new Cat("kis",4,4));
murCat.add(new Cat("push",5,3));
return murCat;
}
public static void printCats(Set<Cat> cats) {
Iterator iterator = cats.iterator(); // Выовод обьектов на экран
while (iterator.hasNext()){
System.out.println(iterator.next());
}
}
// step 1 - пункт 1
public static class Cat{
String name;
int age;
int weight;
public Cat(String name, int age, int weight){
this.name = name;
this.age = age;
this.weight = weight;
}
public String toString()
{
return this.name+ "age - " +this.age + " weight - " + this.weight;
}
}
}
package com.javarush.task.task08.task0819;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/*
Set из котов
*/
public class Solution {
public static void main(String[] args) {
Set<Cat> cats = createCats();
//напишите тут ваш код. step 3 - пункт 3
cats.remove(cats.iterator().next());
printCats(cats);
}
public static Set<Cat> createCats() {
//напишите тут ваш код. step 2 - пунк
HashSet<Cat> murCat = new HashSet<>();
murCat.add(new Cat("mur",3,5));
murCat.add(new Cat("kis",4,4));
murCat.add(new Cat("push",5,3));
return murCat;
}
public static void printCats(Set<Cat> cats) {
Iterator iterator = cats.iterator(); // Выовод обьектов на экран
while (iterator.hasNext()){
System.out.println(iterator.next());
}
}
// step 1 - пункт 1
public static class Cat{
String name;
int age;
int weight;
public Cat(String name, int age, int weight){
this.name = name;
this.age = age;
this.weight = weight;
}
public String toString()
{
return this.name+ "age - " +this.age + " weight - " + this.weight;
}
}
}