I am new to java and I am trying to do a code where I use scanner to have all my variables been put by the user. The problem is that when i need to put different types as input, the string i print to ask for different types print together and they take the same input in nextInt() or nextString(); it gives me a error because they are a different types. How can i make them to "wait" for their turn?
package ese_9;
import java.util.Scanner;
import java.util.ArrayList;
public class main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Quanti clienti si vuole aggiungere?");
int j=input.nextInt();
new ArrayList<Cliente>();
ArrayList<Cliente> gente= new ArrayList<Cliente>();
for (int i=0; i <j;i++ ) {
System.out.println("Inserire nome cliente: ");
String nome= input.nextLine();
System.out.println("Inserire identificativo del cliente: ");
int id=input.nextInt();
System.out.println("Inserire il numero di conto bancario del cliente: ");
int idconto=input.nextInt();
System.out.println("Inserire il saldo iniziale del cliente: ");
double saldo=input.nextDouble();
gente.add(new Cliente(nome, id));
}
System.out.println(gente);
}
}
i will put the class Cliente just to understand better
package ese_9;
public class Cliente {
private String nome;
private int id;
public Cliente(String nome,int i) {
this.nome=nome;
this.id=i;
}
public String getNome() {
return nome;
}
public int getid() {
return id;
}
}