It is written by beginners. If it is good, please use it for reference. If it is not good, Do not spray it!
Bowling points rules:
保龄球一局由10轮组成。球员前9轮中,除了打出全中球外,每轮都有两次投球机会。第10轮全中时再奖励两次投球机会,奖励球的得分应累计在该局的总分内。如果第10轮为补中,则再奖励一次投球机会,所得分同样累计在该局的总分内。如果从第1轮的第一个球到第10轮的两个奖励全部是一次击倒球瓶的话,即为满分300分。
保龄球成绩记录在记分格上。每局球记分格上共有10格,第1格到第9格各有两个小栏。第10格则有三个小栏。第一栏记录的是第一次击倒的球瓶数,或是记载“全中”的符号即[×]。第二栏记录的是第二次击倒的球瓶数或“补中”的符号即[/]。第10格的第三栏只有在第10轮投球“全中”或“补中”时才用得上。特别注意的是记分栏记录的是每轮得分的累计分,而不是每轮的得分。每一格投球可能出现三种情况:
补中。每轮的第一次掷球未能将全部球瓶击倒,第二次掷球将剩余的球瓶全部击倒,称为“补中”。此轮的得分是10分加上下一次掷球击倒的瓶数。如果该轮第一次掷球未得分,第二次掷球将所有球瓶击倒,也算作为补中。
失球。无论何种情况,在一格的两次投球时,未能击倒所有10个瓶,此轮的分数为击倒的瓶数。在每轮第一击球时可能会出现分瓶,即第一次投球击倒部分球瓶(①号球瓶必须被击倒),余下的两个或两个以上球瓶成分开的形状。出现分瓶多数情况会导致失球。
全中。每轮的第一次掷球将全部球瓶击倒,称为“全中”。这一轮就此结束,不再进行第二次掷球。此轮的得分是10分加下两次投球击倒的瓶数。
第十格的记分情况比较特殊:
如果第一球为全中,则追加两次投球机会,第十格得分为10分加上追加两次投球击倒的瓶数。如果第二次投球未补中,则第十格得分为第十格所击倒的瓶数。如果第二次投球补中,则追加一次投球机会,第十格得分为10分加上追加一次投球击倒的瓶数。
代码:
1 package com.fj; 2 3 import java.util.Scanner; 4 5 public class Bowling { 6 public static void main(String[] args) { 7 Scanner sc = new Scanner(System.in); 8 boolean isContinue = true; 9 int[][] innings = new int[11][4]; 10 int flage = 0; 11 for (int i = 0; i < innings.length && isContinue; i++) { 12 for (int j = 0; j < innings[i].length - 2 && isContinue; j++) { 13 System.out.print("请输入第" + ( i + 1) + "局,第" + (j + 1) + "次击打倒的瓶子数目:"); 14 innings[i][j] = sc.nextInt(); 15 if (i <= 9) { 16 if (j == 0) { 17 if (innings[i][j] > 10 || innings[i][j] < 0) { 18 System.out.println("输入错误!"); 19 j--; 20 }else if (innings[i][j] == 10) { 21 if (i == 9) { 22 flage = 2; 23 } 24 j++; 25 } 26 }else { 27 if (innings[i][j] <0 || innings[i][j] > (10 - innings[i][j - 1])) { 28 System.out.println("输入错误!"); 29 j--; 30 }else { 31 if (i == 9) { 32 if (innings[i][j] + innings[i][j - 1] == 10) { 33 flage = 1; 34 } 35 } 36 } 37 38 } 39 if (flage == 0 && i == 9 && j != 0) { 40 isContinue =false; 41 } 42 } 43 else { 44 if (flage == 2) { 45 if (innings[i][j] > 10 || innings[i][j] < 0) { 46 System.out.println("输入错误!"); 47 j--; 48 } 49 else { 50 if (j == 1) { 51 if (innings[i][j - 1] < 10) { 52 if (innings[i][j - 1] + innings[i][j] > 10) { 53 System.out.println("输入错误!"); 54 j--; 55 } 56 } 57 } 58 } 59 } 60 if (flage == 1) { 61 if (innings[i][j] > 10 || innings[i][j] < 0) { 62 System.out.println("输入错误!"); 63 j--; 64 } 65 else { 66 isContinue = false; 67 } 68 } 69 } 70 } 71 } 72 73 for (int i = 0; i < innings.length - 1; i++) { 74 if (i <= 8) { 75 if (innings[i][0] == 10) { 76 if (innings[i + 1][0] == 10) { 77 innings[i][2] = innings[i][0] + innings[i + 1][0] + innings[i + 2][0]; 78 } 79 else { 80 innings[i][2] = innings[i][0] + innings[i + 1][0] + innings[i + 1][1]; 81 } 82 } 83 else if (innings[i][0] + innings[i][1] == 10){ 84 innings[i][2] = innings[i][0] + innings[i][1] +innings[i + 1][0]; 85 } 86 else { 87 innings[i][2] = innings[i][0] + innings[i][1]; 88 } 89 90 91 } 92 if (i == 9) { 93 if (innings[i][0] == 10) { 94 innings[i][2] = innings[i][0] + innings[i + 1][0] + innings[i + 1][1]; 95 } 96 else if (innings[i][0] + innings[i][1] == 10){ 97 innings[i][2] = innings[i][0] + innings[i][1] + innings[i + 1][0]; 98 }else { 99 innings[i][2] = innings[i][0] + innings[i][1];100 }101 }102 if (i == 0) {103 innings[i][3] = innings[i][2];104 }else {105 innings[i][3] = innings[i - 1][3] + innings[i][2];106 }107 }108 System.out.println("轮数\t第一次击倒数\t第二次击倒数 \t本轮得分\t累计得分");109 for (int i = 0; i < innings.length; i++) {110 System.out.print(i + 1 + "\t");111 for (int j = 0; j < innings[i].length; j++) {112 if (j == 2 || j == 1) {113 System.out.print("\t");114 }115 System.out.print(innings[i][j] + "\t");116 }117 System.out.println();118 }119 }120 }
Output:
Enter the number of bottles for 1st innings and 1st hits: 5
Enter the number of bottles for 1st innings and 2nd hits: 5
Enter the number of bottles for 2nd innings and 1st hits: 5
Enter the number of bottles for 2nd innings and 2nd hits: 5
Enter the number of bottles for 3rd innings and 1st hits: 5
Enter the number of bottles for 3rd innings and 2nd hits: 5
Enter the number of bottles for 4th innings and 1st hits: 5
Enter the number of bottles for 4th innings and 2nd hits: 5
Enter the number of bottles for 5th innings and 1st hits: 5
Enter the number of bottles for 5th innings and 2nd hits: 5
Enter the number of bottles for 6th innings and 1st hits: 5
Enter the number of bottles for 6th innings and 2nd hits: 5
Enter the number of bottles for 7th innings and 1st hits: 5
Enter the number of bottles for 7th innings and 2nd hits: 5
Enter the number of bottles for 8th innings and 1st hits: 5
Enter the number of bottles for 8th innings and 2nd hits: 5
Enter the number of bottles for 9th innings and 1st hits: 5
Enter the number of bottles for 9th innings and 2nd hits: 5
Enter the number of bottles for 10th innings and 1st hits: 5
Enter the number of bottles for 10th innings and 2nd hits: 5
Enter the number of bottles for 11th innings and 1st hits: 5
Round count first knock down number second knock down number current round score Cumulative Score
1 5 5 15 15
2 5 5 15 30
3 5 5 15 45
4 5 5 15 60
5 5 5 15 75
6 5 5 15 90
7 5 5 15 105
8 5 5 15 120
9 5 5 15 135
10 5 5 15 150
11 5 0 0 0
Bowling for scores