私はバスケットボールでリンクされたバッグの削除メソッドに渡しています。私はすでに渡されたものと同じオブジェクトをチェックしています。私は方法が偽を返す理由を把握することができません
public static void removeMain(Scanner input,LinkedBag<Basketball> teamX){
System.out.println("Please enter the team & rank of the object you want to remove.");
System.out.println("Team?");
String team = input.nextLine();
System.out.println("Rank?");
int rank = input.nextInt();
input.nextLine();
if(teamX.remove(new Basketball(team, rank))){
System.out.println("REMOVED!");
}else{
System.out.println("Team was not found due to it not being in the list.");
}
}
public boolean remove(E target){
boolean found = false;
int i = 0;
Node<E> pointer = head;
Node<E> previous = head;
while (pointer != null && !found){
if((pointer.getData()).equals(target)){
found = true;
}else{
pointer = pointer.getLink();
if(i>0){
previous = previous.getLink();
}
i++;
}
}
if(found){
previous.setLink(pointer.getLink());
numElements--;
}
return found;
}
これはバスケットボールのクラス
パブリッククラスバスケットボールがComparableを
public int compareTo(Basketball anotherTeam)
throws ClassCastException
{
if (!(anotherTeam instanceof Basketball))
throw new ClassCastException("A Car object expected.");
if (getRanking() < anotherTeam.getRanking())
return -1;
else if (getRanking() > anotherTeam.getRanking())
return 1;
else
return team.compareToIgnoreCase(anotherTeam.getTeam());
}
コードを画像としてではなく、画像として投稿してください。 –
どうすればいいですか? –
テキストをコピーして投稿に貼り付けてください。 –