Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Corn Hole is a game with simple scoring rules: There are two teams. A round consists of each team throwing four bean bags at a

Corn Hole is a game with simple scoring rules:

There are two teams.

A round consists of each team throwing four bean bags at a corn hole board.

During a round, each team counts:

3 points for each bean bag that drops through the hole.

1 point for each bean bag that lands and stays on the board (but does not go through the hole).

0 points for each bean bag that ends up on the ground.

Only one team can score any points in a round. The score for the round is the difference in points between the two teams totals. So, if Team 1 scores 4 points and Team 2 scores 3 points, then the score for the round is 1 point for Team 1.

The two teams keep playing rounds until one team scores 21 or more points. That team is the winner.

Here are some example rounds and the resulting score:

Team 1: 0,0,0,0 (all bags on ground). Team 2: 0,0,0,0 (all bags on ground). Score: No points for either team.

Team 1: 0,0,0,1 (1 bag on corn hole). Team 2: 0,0,0,0 (all bags on ground). Score: 1 point for Team 1.

Team 1: 3,3,1,1 (two bags in hole, other two bags on corn hole). Team 2: 1,1,1,1 (all bags on corn hole). Score: 4 points for Team 1.

Team 1: 3,1,0,0 (one in hole, one on corn hole). Team 2: 1,1,1,1 (all bags on corn hole). Score: no points for either team.

For this WOD, please write two Javascript classes that together implement these rules for scoring corn hole:

Round. Objects created from the Round class represent the points awarded for each of the four tosses by the two teams. The constructor for this class should take a two arguments: team1 which is an array of four integers, and team2 which is also an array of four integers. You can assume that the only integers in these arrays are 0, 1, or 3.

Game. Objects created from the Game class implement a way to represent all of the Rounds, as well as the total Score for the game.

The Round class has the following methods in addition to its constructor:

scoreTeam1(). Returns the score for Team 1 for this round.

scoreTeam2(). Returns the score for Team 2 for this round.

Note that the score for (at least) one of the teams will always be 0. Only one team is awarded points in any given round.

The Game class has the following methods in addition to its constructor:

addRound(round). Adds a Round instance to this Game instance.

totalScoreTeam1(). Returns the total score for Team 1 for this game.

totalScoreTeam2(). Returns the total score for Team 2 for this game.

getWinner(). Return Team 1 if Team 1 has 21 or more points, or Team 2 if Team 2 has 21 or more points, or No winner.

Here is code you can use to test parts of your implementation

const round1 = new Round([3,3,1,1], [0,0,1,1]); console.log(round1.scoreTeam1()); // prints '6'. console.log(round1.scoreTeam2()); // prints '0' const round2 = new Round([1,1,1,1], [1,1,1,0]); console.log(round2.scoreTeam1()); // prints '1' console.log(round2.scoreTeam2()); // prints '0' const game = new Game(); game.addRound(round1); game.addRound(round2); game.addRound(new Round([3,3,3,3], [0,0,0,0])); game.addRound(new Round([3,3,1,1], [1,1,0,0])); console.log(game.totalScoreTeam1()); // prints 25 console.log(game.totalScoreTeam2()); // prints 0 console.log(game.getWinner()); // prints 'Team 1'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

Evaluate the importance of diversity in the workforce.

Answered: 1 week ago

Question

Identify the legal standards of the recruitment process.

Answered: 1 week ago