java - how to Add members to the Team -


i want program go menu when switch cases has been completed or on don't know how it. here's code. example, when user has chosen his/her choice , he/she has performed program closes automatically, don't want want continue until user wishes exit program. please don't know do

    public class jproj     {         public static void main(string[] args)         {             boolean = false;             string teamone = null;             string teamtwo = null;             linkedlist x = new linkedlist();             string name;             int team;             char choice = 'w';               int num=0;             system.out.println("menu");             system.out.println("a.) add member");             system.out.println("b.) define friends of each member");             system.out.println("c.) create 2 teams");             system.out.println("d.) save data");             system.out.println("e.) extract data file");             sysmte.out.println("f.) exit");             scanner ans = new scanner(system.in);             system.out.print("choice:");               choice = ans.next().charat(0);               switch(choice)              {         case 'a':              scanner = new scanner(system.in);             system.out.println("adding members");             system.out.print("name of member:");             name = a.nextline();             system.out.println(""+name);                  x.insert(name);                 x.displayone();                 system.out.print("successfull!");                 break;         case 'b':             system.out.println("defining friends of members");             break;         case 'c':             system.out.print("creating teams");             scanner scanner = new scanner(system.in);             if(teamone!=null&&teamtwo!=null)             {                 system.out.print("teams has been created!\n want replace team names?");                 system.out.print("1-yes\n2-no");                  int sagot = scanner.nextint();                 if(sagot != 1)                 {                     return;                 }                 else                     system.out.println("creating teams");                     scanner c = new scanner(system.in);                     system.out.print("enter new name of team 1:");                     teamone = c.nextline();                     system.out.print("enter new name of team 2:");                     teamtwo = c.nextline();                     x.teamname(teamone,teamtwo);             }             else                     system.out.println("creating teams");                     scanner c = new scanner(system.in);                     system.out.print("name of team 1:");                     teamone = c.nextline();                     system.out.print("name of team 2:");                     teamtwo = c.nextline();                     x.teamname(teamone,teamtwo);                     system.out.print("teams has been created!");                     system.out.print("current members:");                     x.displaytwo();             break;         case 'd':             system.out.println("saving data");             break;         case 'e':             break;         case 'f':             return;             enter code herebreak;       }     } } 

do {     system.out.println("menu");     system.out.println("a.) add member");     system.out.println("b.) define friends of each member");     system.out.println("c.) create 2 teams");     system.out.println("d.) save data");     system.out.println("e.) extract data file");     sysmte.out.println("f.) exit");     choice = ans.next().charat(0);      switch(choice){         case 'a':          system.out.println("adding members");         system.out.print("name of member:");         name = ans.nextline();         system.out.println(""+name);              x.insert(name);             x.displayone();             system.out.print("successfull!");             break;     case 'b':         system.out.println("defining friends of members");         break;     case 'c':         system.out.print("creating teams");         if(teamone!=null&&teamtwo!=null)         {             system.out.print("teams has been created!\n want replace team names?");             system.out.print("1-yes\n2-no");              int sagot = ans.nextint();             if(sagot != 1)             {                 return;             }             else                 system.out.println("creating teams");                 system.out.print("enter new name of team 1:");                 teamone = ans.nextline();                 system.out.print("enter new name of team 2:");                 teamtwo = ans.nextline();                 x.teamname(teamone,teamtwo);         }         else                 system.out.println("creating teams");                 system.out.print("name of team 1:");                 teamone = ans.nextline();                 system.out.print("name of team 2:");                 teamtwo = ans.nextline();                 x.teamname(teamone,teamtwo);                 system.out.print("teams has been created!");                 system.out.print("current members:");                 x.displaytwo();         break;     case 'd':         system.out.println("saving data");         break;     case 'e':         break;     default:             system.out.println("invalid option");         break;     } while (choice != 'f'); 

use loop, in case i'm using while loop reloop menu. bring down println options prints menu user see again. choice should inside loop too.

also creating lot of same scanner object, need 1 , can re-use since of them using system.in, wasting memory space creating same objects same use. in case codes, i'm using using "ans" variable stores scanner(system.in) , re-use them of user "system input" (system.in) instead of re-declaring new one.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -