Question: I need some code, don't think it will take long to do. Convert this program to Arraylist, this program is the bowling score calculator code:
I need some code, don't think it will take long to do. Convert this program to Arraylist, this program is the bowling score calculator
code:
Scanner keyIn = new Scanner(System.in); Random gen = new Random(); int frme[] = new int[10]; // Init Frame in a 1 dimension Array int allfrme[][] = new int[2][12]; // Init Frames with 2 Extra Pins in 2 dimension Array String s = null; // Input String do { //A loop to get all input string from user and System.out.println(" \t Welcome to Java Bowling Console Gaming Score Board "); for(int l1 = 0; l1 < 10; l1++) frme[l1] = 0; for(int l2 = 0; l2 < 12; l2++) allfrme[0][l2] = allfrme[1][l2] = 0; nxtfrme: //Init the arrays
for(int i = 0; i < 10; i++) { boolean chk = false; int Pins = gen.nextInt(11);
while(!chk) { //Accepting string inputs and validating it System.out.printf(" \t FRAME %2d ", new Object[] { Integer.valueOf(i + 1) });
//Pins = keyIn.nextInt();
if(Pins <= 10 && Pins >= 0) { allfrme[0][i] = Pins; chk = true; } } if(Pins == 10) { //Displaying to user that he made a Strike when equal to 10 pins System.out.println(" \t\t\tExcelent, Strike!!"); continue;
} chk = false; if(allfrme[0][0] + allfrme[0][1] == 10) frme[0] = 10 + allfrme[0][1]; else frme[0] = allfrme[0][0] + allfrme[1][0];
//middle if(allfrme[0][0] == 10) { if(allfrme[0][1] == 10) frme[0] = 20 + allfrme[0][2]; else frme[0] = 10 + allfrme[0][1] + allfrme[1][1]; }
//end for(int j = 1; j < 10; j++) {
if(allfrme[0][j] == 10){ if(allfrme[0][j + 1] == 10) frme[j] = frme[j - 1] + 20 + allfrme[0][j + 2]; else frme[j] = frme[j - 1] + 10 + allfrme[0][j + 1] + allfrme[1][j + 1]; continue; }
if(allfrme[0][j] + allfrme[1][j] == 10) frme[j] = frme[j - 1] + 10 + allfrme[0][j + 1]; else frme[j] = frme[j - 1] + allfrme[0][j] + allfrme[1][j];
}
//Printing Values System.out.print(" \t FRAME"); // Frame Heading //Init object loops to get and add values to the right address for(int k = 1; k < 11; k++) System.out.printf("%4d", new Object[] { Integer.valueOf(k) });
if(allfrme[0][9] == 10) { if(allfrme[0][10] == 10) System.out.print(" XTR1 XTR2"); else System.out.print(" EXTRA");
}else if(allfrme[0][9] + allfrme[1][9] == 10) System.out.print(" XTRA"); System.out.print(" \tPlayer 1 ");
for(int l = 0; l < 10; l++) System.out.printf("%4d", new Object[] { Integer.valueOf(allfrme[0][l]) }); //Displaying the array addresses in each frame. if(allfrme[0][9] == 10) { if(allfrme[0][10] == 10) System.out.printf("%4d%4d", new Object[] { Integer.valueOf(allfrme[0][10]), Integer.valueOf(allfrme[0][11]) }); else System.out.printf("%4d", new Object[] { Integer.valueOf(allfrme[0][10]) });
} else if(allfrme[0][9] + allfrme[1][9] == 10) System.out.printf("%4d", new Object[] { Integer.valueOf(allfrme[0][10]) }); System.out.print(" \tPlayer 2 "); for(int i1 = 0; i1 < 10; i1++) System.out.printf("%4d", new Object[] { Integer.valueOf(allfrme[1][i1]) });
if(allfrme[0][9] == 10 && allfrme[0][10] != 10) System.out.printf("%4d", new Object[] { Integer.valueOf(allfrme[1][10]) });
System.out.print(" \t SCORE"); for(int j1 = 0; j1 < 10; j1++) System.out.printf("%4d", new Object[] { Integer.valueOf(frme[j1]) }); //Prompt to the user System.out.print(" \t\t\tPlay more (Y/N)? "); s = keyIn.next(); String s1 = keyIn.nextLine(); if(s1 =="N") { break; }
} }while(s.toUpperCase().charAt(0) != 'N'); }
Convert to ArrayList. Do not use throw, try execption.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
