my exercise is with collect soccer cards inside an arraylist.
inside my code I have to insert the methods: "add, search, remove, print and modify
".
From input I must save all data of name of player, surname and country after that from output someone can ask me about player so i can tell it from code.
My problem is i can't add some thing from input and i don't know how to continue with another methods after input with Scanner
.
MAIN:
package figurines;
import java.util.*;
public class Figurines {
public ArrayList<Giocatori> lista = new ArrayList<Giocatori>();
public static void main(String[] args) {
System.out.println("1 Penaldo 2 Pessi 3 Neymar 4 Buffon");
Scanner searchBar = new Scanner(System.in);
System.out.println("Inserisci I dati del giocatore");
String search = searchBar.nextLine().toUpperCase();
for (Giocatori liste : lista) {
if (liste.getCognome().equalsIgnoreCase(search)) {
System.out.println(" Nome = " + liste.getNome() +" Paese= " + liste.getPaese());
}
}
}
}
CLASS WHERE I CAN ADD METHODS
package figurines;
import java.util.*;
public class Gestione {
public void input(){
ArrayList<Giocatori> list = new ArrayList<Giocatori>();
Scanner tastiera = new Scanner(System.in);
System.out.println("Inserisci il nome del giocatore: ");
String name;
String surname;
Scanner input = new Scanner(System.in);
System.out.println("Please Enter first name: ");
name = input.nextLine();
System.out.println("Please Enter last name: ");
surname = input.nextLine();
}
}
SOME ARRAY METHODS:
package figurines;
import java.util.*;
public class Giocatori {
private String nome;
private String cognome;
private String paese;
public Giocatori(String nome, String cognome, String paese) {
this.nome = nome;
this.cognome = cognome;
this.paese = paese;
}
public String getNome() {
return nome;
}
public String getCognome() {
return cognome;
}
public String getPaese() {
return paese;
}
}
question from:
https://stackoverflow.com/questions/65904369/exercise-with-arraylist-input-with-scanner 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…