I'm trying to call the start () method in this own method using Scanner. Once the user enters a number a sequence of actions are performed and then I would like the start () method to be called again. Except I get this error :
My code :
public void start() {
System.out.println("1. Créer un nouveau réseau");
System.out.println("2. Créer un nouvel ordi portable");
System.out.println("3. Créer un nouvel ordi fix");
System.out.println("4. Créer un Switch \n");
System.out.print("Choisir un chiffre : ");
Scanner scan = new Scanner(System.in);
if(scan.hasNextInt()) {
int v = scan.nextInt();
switch(v) {
case 1:
addNetwork();
scan.next();
start();
break;
}
} else {
System.out.println("Vous devez rentrer un chiffre !");
scan.next();
start();
}
}
EDIT :
Here is the full output of the program :
EDIT :
My addNetwork method :
private void addNetwork() {
System.out.print("Quel est l'IP du réseau ? ");
Scanner scan = new Scanner(System.in);
String ip = scan.nextLine();
System.out.print("Quel est le masque du réseau ? (par défaut /24) ");
String mask = scan.nextLine();
scan.close();
web.addNetwork(ip, mask);
}