„Rzeczywiste lub formalne listy argumentów różnią się długością”
Kiedy próbuję umieścić coś w nawiasach ()Friends f = new Friends(friendsName, friendsAge);
pojawia się błąd:
Przyjaciele konstruktora w klasie Przyjaciele nie mogą być zastosowani do danych typów. Wymagane: brak argumentów. Znaleziono: String, int. Powód: rzeczywiste lub formalne listy argumentów różnią się długością.
Ale kiedy usuwam argumenty, lista moich znajomych wyświetla tylko „zero”. Czy wartości nie są ustawione, mimo że mamString friendsName = input.next();
?
Ponadto, gdy próbuję usunąć przyjaciela, nic nie robi. W kodzie źródłowym wyświetla ostrzeżenie,
Podejrzane wywołanie do util.java.Collection.remove: Podany obiekt nie może zawierać podanych instancji String (oczekiwane Friends).
Jestem zdezorientowany, co to wszystko znaczy?
import java.util.ArrayList;
import java.util.Scanner;
public class Friends
{
public static void main( String[] args )
{
int menu;
int choice;
choice = 0;
Scanner input = new Scanner(System.in);
ArrayList< Friends > friendsList = new ArrayList< >();
System.out.println(" 1. Add a Friend ");
System.out.println(" 2. Remove a Friend ");
System.out.println(" 3. Display All Friends ");
System.out.println(" 4. Exit ");
menu = input.nextInt();
while(menu != 4)
{
switch(menu)
{
case 1:
while(choice != 2)
{
System.out.println("Enter Friend's Name: ");
String friendsName = input.next();
System.out.println("Enter Friend's Age: ");
int friendsAge = input.nextInt();
Friends f = new Friends(friendsName, friendsAge);
friendsList.add(f);
System.out.println("Enter another? 1: Yes, 2: No");
choice = input.nextInt();
} break;
case 2:
System.out.println("Enter Friend's Name to Remove: ");
friendsList.remove(input.next());
break;
case 3:
for(int i = 0; i < friendsList.size(); i++)
{
System.out.println(friendsList.get(i).name + " " + friendsList.get(i).age);
} break;
}
System.out.println(" 1. Add a Friend ");
System.out.println(" 2. Remove a Friend ");
System.out.println(" 3. Display All Friends ");
System.out.println(" 4. Exit ");
menu = input.nextInt();
}
System.out.println("Thank you and goodbye!");
}
public String name;
public int age;
public void setName( String friendsName )
{
name = friendsName;
}
public void setAge( int friendsAge )
{
age = friendsAge;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}