主なプログラムはこちら
public class MainPerson {
public MainPerson(){}
public static void StartMainPerson()
{
int i = 1;
ArrayList<SortedPair> PersonList;
ArrayList<Person> InitializedPersonList;
final int NUMBER_OF_PEOPLE = 6;
PersonList = new ArrayList<>();
InitializedPersonList = new ArrayList<>();
InitializedPersonList.add(new Person( "Assaf Malki" , 1984));
InitializedPersonList.add(new Person( "Assaf Malki" , 1984));
InitializedPersonList.add(new Person( "Breanna Romberger" , 1920));
InitializedPersonList.add(new Person( "Latrice Lane" , 1930));
InitializedPersonList.add(new Person( "Bridgett Couch" , 1940));
InitializedPersonList.add(new Person( "Roxane Sova" , 1950));
InitializedPersonList.add(new Person( "Donnette Weston" , 1960));
InitializedPersonList.add(new Person( "Milton Kopecky" , 1970));
InitializedPersonList.add(new Person( "Rosella Vandoren" , 1980));
InitializedPersonList.add(new Person( "Kayleigh Willimas" , 1990));
InitializedPersonList.add(new Person( "Zula Lashua" , 2000));
InitializedPersonList.add(new Person( "Ralph Baudoin" , 2010));
InitializedPersonList.add(new Person( "Kenton Tseng" , 2005));
InitializedPersonList.add(new Person( "Brendon Gilchrest" , 1995));
Iterator itr = InitializedPersonList.iterator();
while(itr.hasNext())
{
System.out.print("Pair " + i + " is " + itr.next() + " and " + itr.next() + ".\n");
i = i + 1;
}
i = 0;
System.out.print("\n");
Iterator itr1 = InitializedPersonList.iterator();
while(i < NUMBER_OF_PEOPLE)
{
try{
System.out.println("Adding pair number " + (i+1) + "..");
PersonList.add(new SortedPair((Person) itr1.next(), (Person) itr1.next()));
}
catch (IllegalPair e)
{
System.out.println("Invalid input, same person name, try again.");
continue;
}
i = i + 1;
}
System.out.println("");
for (SortedPair Value : PersonList)
{
System.out.println(Value);
}
}
}
ここにSortedPairがあります
public class SortedPair <E extends Comparable<E>>
{
E Max_Element;
E Min_Element;
public SortedPair(E FirstElement, E SecondElemnt) throws IllegalPair
{
int Compare_Result = FirstElement.compareTo(SecondElemnt);
if (Compare_Result == 0)
{
Max_Element = null;
Min_Element = null;
throw new IllegalPair(FirstElement.toString(), SecondElemnt.toString());
}
else if (Compare_Result > 0)
{
Max_Element = FirstElement;
Min_Element = SecondElemnt;
}
else
{
Max_Element = SecondElemnt;
Min_Element = FirstElement;
}
}
public E getFirst()
{
return Max_Element;
}
public E getSecond()
{
return Min_Element;
}
@Override
public String toString()
{
return String.format("%s is bigger then %s.", getFirst(), getSecond());
}
}
次の警告が表示されます
MainPerson.java:60: warning: [unchecked] unchecked call to SortedPair(E,E) as a member of the raw type SortedPair
PersonList.add(new SortedPair((Person) itr1.next(), (Person) itr1.next()));
^
where E is a type-variable:
E extends Comparable<E> declared in class SortedPair
そして、私は方法を理解していません。
に変更しようとしArrayList<Person> InitializedPersonList;
ましArrayList<Comperable> InitializedPersonList;
たが、うまくいきませんでした。
アイデアはありますか?
質問はかなり明確だと思います.どれだけのテキストを追加できますか Common..