Я пытаюсь найти самого недавнего участника, присоединившегося к моему списку людей в спортивном клубе. Мой мыслительный процесс находит самый высокий год, а затем самый высокий месяц, но у меня возникают проблемы с его выполнением.
Вот члены клуба:
club.join(new Membership("Ellen", 2, 2016, 115.00));
club.join(new Membership("Eric", 1, 2017, 75.00));
club.join(new Membership("Ben", 3, 2015, 35.50));
club.join(new Membership("Matt", 12, 2014, 42.00));
club.join(new Membership("Luke", 5, 2010, 145.00));
club.join(new Membership("Jon", 6, 2017, 65.00));
club.join(new Membership("Ryan", 7, 2016, 0.00));
club.join(new Membership("Alan", 8, 2015, 195.00));
club.join(new Membership("Jaden", 9, 2015, 15.00));
club.join(new Membership("Dan P", 10, 2011, 25.00));
club.join(new Membership("Jack", 2, 2013, 80.75));
club.join(new Membership("Mrs. R", 1, 2014, 125.00));
club.join(new Membership("Dan S", 1, 2015, 45.00));
club.join(new Membership("Caleb", 10, 2016, 0.00));
club.join(new Membership("Jacob", 5, 2017, 10.00));
club.join(new Membership("Anny", 7, 2016, 110.00));
club.join(new Membership("Wendy", 7, 2015, 85.00));
club.join(new Membership("Natalie", 8, 2014, 0.00));
club.join(new Membership("Paul", 9, 2016, 20.00));
club.join(new Membership("Zuck", 10, 2017, 55.00));
А вот мой код для поиска самого последнего метода:
int tempMonth = 13;
int tempYear = 3000;
ArrayList<Membership> ppl = new ArrayList<Membership>();
Iterator<Membership> itr = members.iterator();
while(itr.hasNext())
{
Membership item = itr.next();
if(members.size() == 0)
{
return null;
}
else
{
if(tempYear > item.getYear())
{
if(tempMonth > item.getMonth())
{
ppl.add(item);
itr.remove();
}
}
}
}
return ppl;