问题描述
importjava.util.*;publicclassPrison{privatestaticDatetoday;privatebooleanquit;privatePrisoner[]prisoners=newPrisoner[10];publicintindex=0;privatedoublecellNo;intd=1;privateDate[]dates=newDate[20];privateString[]prisonerDetail=newString[5];privateString[]cellDetail=newString[5];privatestaticvoidstart(){today=newDate(1,1,2011);}publicstaticDatetoday(){returntoday;}publicstaticvoidmain(Stringargs[]){newPrison();}publicintindex(){returnindex;}publicPrison(){start();action();while(quit!=true){readChoose();}}publicvoidaction(){System.out.println("ShortBayPrison");}privatevoidreadChoose(){System.out.print("nAction(or?):");charnextIn=Character.toUpperCase(In.nextChar());switch(nextIn){case'N':add();break;case'A':allocate();break;case'P':showDetails();break;case'C':showCell();break;case'?':explain();break;case'X':exit();break;default:error();}}privatevoidadd(){Stringn,c;intl;intday=0;intm=0;inty=0;inttotal=0;System.out.print("name:");n=In.nextLine();System.out.print("Crime:");c=In.nextLine();System.out.print("Level:");l=In.nextInt();System.out.print("Days:");day=In.nextInt();System.out.print("Months:");m=In.nextInt();System.out.print("Years:");y=In.nextInt();total=day+(m*30)+(y*365);dates[index]=newDate(today());dates[index].add(total);prisoners[index]=newPrisoner(n,c,l,d);Strings=""+d+""+n+"n"+c+":"+"start"+today()+",end"+dates[index]+",period"+day+"/"+m+"/"+y;System.out.print(s);prisonerDetail[index]=s;index++;d++;}privatevoidallocate(){intb;System.out.print("Prisonerid(0toexit):");d=In.nextInt();}publicvoidshowDetails(){intc=0;System.out.print("Theprisonersare");for(inti=0;i<prisonerDetail.length;i++)if(prisonerDetail[i]==(null)){prisonerDetail[i]="";c++;if(c==prisonerDetail.length)System.out.println("nnone");}else{System.out.println("n"+prisonerDetail[i]);}}privatevoidshowCell(){intc=0;System.out.print("Cellallocationis");for(inti=0;i<cellDetail.length;i++)if(cellDetail[i]==(null)){cellDetail[i]="";c++;if(c==cellDetail.length)System.out.println("nnone");}else{System.out.println("n"+cellDetail[i]);}}privatevoidexplain(){System.out.print("Thechoicesare"+"n"+"N:Newprisoner"+"n"+"A:Allocateacell"+"n"+"P:Showprisoners"+"n"+"C:Showcellallocation"+"n"+"?:Explainthechoices"+"n"+"X:Exitthesystem"+"n");}publicvoiderror(){System.out.println("Thatwasnotavalidchoice.");System.out.print("nEnteranewaction(?forhelp).");}publicvoidexit(){quit=true;System.exit(0);}}以上是我代码,在allocation那一块,要求在这个有2层楼,一层10个房间,单数房间放1个犯人,双数房间能放2个犯人,3个不同级别的犯人不能关在一起,同级别的可以关在偶数房间里,房间代码是1.1;1.2;.....1.102.1;2.2...2.20跪求高手解答,在线坐等这是要求的运行时的模板求高手解答.....十万火急ShortBayPrisonAction(or?):?ThechoicesareN:NewprisonerA:AllocateacellP:ShowprisonersC:Showcellallocation?:ExplainthechoicesX:ExitthesystemAction(or?):erThatwasnotavalidchoice.Enteranewaction(?forhelp).Action(or?):pTheprisonersarenoneAction(or?):cCellallocationisnoneAction(or?):xShortBayPrisonAction(or?):nName:fredCrime:litteringLevel:1Days:3Months:0Years:01fredlittering:start1/1/2011,end4/1/2011,period3/0/0Action(or?):aPrisonerid(0toexit):1fredisintheonlybunkofcell1.1Action(or?):nName:johnCrime:arsonLevel:3Days:2Months:3Years:42johnarson:start1/1/2011,end2/4/2015,period2/3/4Action(or?):aPrisonerid(0toexit):2johnisinthetopbunkofcell1.2Action(or?):nName:tomCrime:badhairLevel:1Days:4Months:0Years:03tombadhair:start1/1/2011,end5/1/2011,period4/0/0Action(or?):aPrisonerid(0toexit):3tomisintheonlybunkofcell1.3Action(or?):pTheprisonersare1fredlittering:start1/1/2011,end4/1/2011,period3/0/02johnarson:start1/1/2011,end2/4/2015,period2/3/43tombadhair:start1/1/2011,end5/1/2011,period4/0/0Action(or?):cCellallocationisCell1.1has1fredCell1.2has2johnCell1.3has3tomAction(or?):nName:georgeCrime:assaultLevel:3Days:2Months:3Years:14georgeassault:start1/1/2011,end2/4/2012,period2/3/1Action(or?):aPrisonerid(0toexit):4georgeisinthebottombunkofcell1.2Action(or?):cCellallocationisCell1.1has1fredCell1.2has2john,4georgeCell1.3has3tomAction(or?):aPrisonerid(0toexit):43Thatwasnotavalidid.Valididsare1,2,3,4Prisonerid(0toexit):0Action(or?):aPrisonerid(0toexit):11fredalreadyhasacell.TryagainPrisonerid(0toexit):0Action(or?):x
解决方案
解决方案二:
一团浆糊,不知所云。
解决方案三:
希望你能把代码的核心部分贴出来,你贴这么长让人感觉到畏惧