I created a program for taking a criminal case and storing it, and then I added another switch to it so that I can access other stuff I wish to add in the program. But there seems to be an error when the choice is executed. Switch just won't recognize my choice, and instead repeats the menu that resides within the loop. There's no error during compilation. Here's the coding...
import java.util.ArrayList;
import java.util.Scanner;
public class CriminalCase {
private String batput;
public String getBatput(){return batput;}
public CriminalCase(String batput){
this.batput = batput;
}
private static class robin{
String Batman(){
Scanner s=new Scanner (System.in);
System.out.println();
System.out.println("Enter name.");
String a=s.nextLine();
System.out.println("Enter Date of birth.");
String b=s.nextLine();
System.out.println("Enter Sex.");
String c=s.nextLine();
System.out.println("Enter Crime Committed.");
String d=s.nextLine();
System.out.println("Enter Date of Crime Committed.");
String e=s.nextLine();
System.out.println("Enter Victim.");
String f=s.nextLine();
System.out.println();
String g=""+"\n"+""+"Name:- "+a +"\nDOB:- "+b +"\nSex:- "+c +"\nCrime Committed:- "+d +"\nDate of Crime Committed:- "+e +"\nVictim:- "+f;
System.out.println();
return g;
}
}
public static void main(String[] args) {
ArrayList<CriminalCase> cases = new ArrayList<>();
boolean quit = false;
Scanner s = new Scanner(System.in);
robin j=new robin();
boolean exit=false;
for(;!exit;){
System.out.println("For cases press 1.\nFor printing thank you, press 2.\nTo exit, press 3.");
int choice=s.nextInt();
switch (choice){
case 1:{
while (!quit) {
System.out.println();
System.out.println("To view current cases enter v\nto add a case enter a\nto quit enter q");
String input = s.nextLine();
switch(input){
case ("v"): {
System.out.println("");
System.out.println("The following cases exist:");
System.out.println("\nName:- Batman\nDOB:- Unknown\nSex:- Male\nCrime Committed:- Tresspassing a crime scene, Fleeing scene of crime, Carrying unlicensed vehicles and
weapons.\nDate of Crime Committed:- 18/9/2015\nVictim:- None.");
for (CriminalCase c : cases)
System.out.println(c.getBatput());
break;
}
case("a"):{
String batput=j.Batman();
cases.add(new CriminalCase(batput));
break;
}
case("q"):{
quit = true;
}
}
}
break;
}
case 2:System.out.println("Thank you.");
break;
case 3:exit=true;
}
}
}
}