java - User input from scanner method to array of 5 indexes also gives user ability to delete any index -


user input scanner method array of 5 indexes gives user ability delete index matching string 1 of index. want achieve in in while loop settle city (option 1), means creating 1 can see code. user type name no restrictions. once settle city loops starts again. remember user created city earlier. can have upto 5 cities. there cost associate settling new city. know how conditionals. not sure string array.

arraylist or array class not allowed.

where as, option 2 can demolish of city have created giving user lists of city have made earlier. have keep minimum of @ least 1 city.

if wondering based on civilization game.

please ask clarification may not straight forward. thanks

while (playing) {             system.out.println("\nplease make selection!");             system.out.println("\n1. settle city"                 + "\n2. demolish city"                 + "\n3. build militia"                 + "\n4. research technology"                 + "\n5. attack enemy city"                 + "\n6. end turn\n");              string gamechoice = userinput.nextline();              if (gamechoice.equals("1")) {                 system.out.println("\nwhat to"                     + " name city?");                  string cityname = userinput.nextline();                 cityname = citynames[0];                 } else if (gamechoice.equals("2")) {                 system.out.println("what city demolish?");                  (int = 0; < 5 ; i++) {                     system.out.print(citynames[i]);                     system.out.print("");                 }                 } else if (gamechoice.equals("3")) {                 system.out.println("you have military points");              } else if (gamechoice.equals("4")) {                 system.out.println("you have research technology points");              } else if (gamechoice.equals("5")) {                 system.out.println("you have 0 points");              } else {                 system.out.println(" playing ");              }                 playing = false;         } 

first, here:

string cityname = userinput.nextline(); cityname = citynames[0]; 

you assigning cityname user input , assigning in citynames array, doesn't make sense, maybe pasted wrong or something, in case, should other way around, this:

citynames[0] = cityname; 

you have playing = false @ end loop gonna end when user types city name, need either remove playing = false or use continue; after citynames[0] = cityname;, that's gonna go next iteration of loop, without going way down playing = false.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -