glibwon

Category: Line-Based File Processing
Author: Brett Wortzman
Book Chapter: 5.4
Problem: glibwon
In the game of glibwon, each player takes 10 rounds trying to score as many points as possible. In each round, a player can score up to ten points. If a player scores ten points in a round, it is called a mark. There are two types of marks, both worth ten points's kerits and seraps. If a player scores a serap, he or she gets 10 points, and also gets a bonus equal to his or her score in the next round. If a player scores a skerit, he or she gets 10 points and a bonus equal to twice his or her score in the next round. If a player gets a mark in the 10th round, they get an extra round to earn their bonus points.
(a) (14 points)
Write a static method scoreGame that scores a game of glibwon for a single player. The method should take a single string argument that is a player's name followed by his or her score for each round. Non-marks are represented by a digit (0-9), seraps are represented by a slash (/), and skerits are represented by an X. The method should print out the player's name, their score, and the number of marks earned, then return the player's score. The following table
shows some possible calls to scoreGame.

     +------------------------------+------------------------+---------+
     | If str is:                   | scoreGame(str) prints  | Returns |
     +------------------------------+------------------------+---------+
     | Brett 8 9 7 9 / 8 X 9 8 7    | Brett: 111 (2 marks)   | 111     |
     +------------------------------+------------------------+---------+
     | Will  9 9 / X 8 7 8 8 / 9    | Will: 123 (3 marks)    | 123     |
     +------------------------------+------------------------+---------+
     | Chris X X X 8 9 6 7 X 5 8    | Chris: 149 (4 marks)   | 149     |
     +------------------------------+------------------------+---------+
     | Maia  8 8 9 9 X / 7 8 9 / 8  | Maia: 123 (3 marks)    | 123     |
     +------------------------------+------------------------+---------+
     | Dian  9 9 8 7 / 9 8 7 7 X 8  | Dian: 109 (2 marks)    | 109     |
     +------------------------------+------------------------+---------+

You should match this output format exactly. You may assume the string is properly formatted and represents a proper game (i.e. either 10 or 11 round). You do not need to worry about singular or plural.

(b) (7 points)
Using scoreGame, write a static method scoreTeam that takes a Scanner for an input file as a parameter. The input file will contain a team name on the first line, followed by glibwon games for each player on the team. The method should print out each player's score, and then print the team's total score.

For example, if the input file team142.txt contains the following:

     Team CSE 142
     Brett 8 9 7 9 / 8 X 9 8 7
     Will  9 9 / X 8 7 8 8 / 9
     Chris X X X 8 9 6 7 X 5 8
     Maia  8 8 9 9 X / 7 8 9 / 8
     Dian  9 9 8 7 / 9 8 7 7 X 8

Then the call scoreTeam(new Scanner(new File("team142.txt")) would output:

     Brett: 111 (2 marks)
     Will: 123 (3 marks)
     Chris: 149 (4 marks)
     Maia: 123 (3 marks)
     Dian: 109 (2 marks)

     Team CSE 142 Total: 615

You should match this output format exactly. You may assume scoreGame works correctly, regardless of what you wrote in part (a).