Question

In: Computer Science

Top-down design: Design a program called TeamGame to simulate a simple game of drafting players to...

Top-down design: Design a program called TeamGame to simulate a simple game of drafting players to teams. Rules of the game: • There are two teams: Team A and Team B. • There are 50 players, with numbers from 1 to 50. • Each team will get 10 of the players. The program should randomly select 10 players for each team. To accomplish this, you may select each player randomly, or you may shuffle the list of players before making teams. Note that selecting a player does two things: Adds a player to a team, and removes that player from the list of available players. • The team with the minimum sum of player numbers wins the game.
Your program should display: • a list of the players on each team
• the remaining undrafted players (30 players should remain) • the name of the winning team
Use java, Write the full code for the TeamGame program. Develop appropriate methods for your subproblems.

Solutions

Expert Solution

/*********************************************TestGame.java********************************/

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class TestGame {

   // Two list for teamA and teamB
   static ArrayList<Integer> teamA;
   static ArrayList<Integer> teamB;

   public static void main(String[] args) {

       // List of players
       ArrayList<Integer> playerNumber = new ArrayList<>();
       teamA = new ArrayList<>();
       teamB = new ArrayList<>();

       // fill the list
       for (int i = 1; i <= 50; i++) {

           playerNumber.add(i);
       }
       // calling makeTeam method
       makeTeam(playerNumber);
       System.out.println("Team A = " + teamA);
       System.out.println("Team B = " + teamB);
       System.out.println("Remaining players: " + playerNumber);
       // select the winner
       selectWin();
   }

   /*
   * Make two teams from a list of players
   */
   private static void makeTeam(ArrayList<Integer> playerNumber) {

       Collections.shuffle(playerNumber);
       Random random = new Random();

       for (int i = 0; i < 10; i++) {

           int number = playerNumber.get(random.nextInt(playerNumber.size()));
           teamA.add(number);
           playerNumber.remove(new Integer(number));

       }
       for (int i = 0; i < 10; i++) {

           int number = playerNumber.get(random.nextInt(playerNumber.size()));
           teamB.add(number);
           playerNumber.remove(new Integer(number));

       }

   }

   // calculate the score and select the winner
   private static void selectWin() {

       int totalScoreA = 0, totalScoreB = 0;

       for (Integer integer : teamA) {

           totalScoreA += integer;
       }

       for (Integer integer : teamB) {

           totalScoreB += integer;
       }

       if (totalScoreA > totalScoreB) {

           System.out.println("Team A Wins and Score of Team A = " + totalScoreA + ", Team B = " + totalScoreB);
       } else {

           System.out.println("Team B wins and Score of Team B = " + totalScoreB + " Team A = " + totalScoreA);
       }
   }
}
/********************************output*******************************/

Team A = [44, 11, 30, 36, 15, 23, 39, 49, 19, 13]
Team B = [8, 37, 14, 26, 3, 6, 18, 43, 41, 50]
Remaining players: [47, 32, 17, 31, 35, 20, 21, 45, 34, 27, 24, 5, 7, 2, 42, 28, 33, 38, 16, 40, 9, 25, 29, 10, 4, 1, 22, 46, 48, 12]
Team A Wins and Score of Team A = 279, Team B = 246

Please let me know if you have any doubt or modify the answer, Thanks and do not forget to Thumbs Up :)


Related Solutions

Design and implement a Python program which will allow two players to play the game of...
Design and implement a Python program which will allow two players to play the game of Tic-Tac-Toe in a 4x4 grid! X | O | X | O -------------- O | O | X | O -------------- X | X | O | X -------------- X | X | O | X The rules for this game is the same as the classic, 3x3, game – Each cell can hold one of the following three strings: "X", "O", or "...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X...
Design a c++ program to simulate the BlackJack game. Rules: 1) single deck, 52 cards -both...
Design a c++ program to simulate the BlackJack game. Rules: 1) single deck, 52 cards -both player and dealer are taking cards off the same deck (the same 52 values). 2) display BOTH cards of the players, and ONE card of the computer. 3) Check for blackjack (starting value of 21 for computer or player) -if either side has a blackjack end of the game, next hand of blackjack 4) Computer must hit if 16 or below. 5) Computer must...
Top-Down Design of a Program in PYTHON Following the process described in the lecture, you should,...
Top-Down Design of a Program in PYTHON Following the process described in the lecture, you should, as a team, perform a top-down design for a program. Then, construct code for the program. Open the Excel file entitled “Lab8-data.xlsx”. This document lists thermodynamic properties of liquid water at varying temperatures and at two different pressures. The properties listed are as follows: Specific volume (v ) in units of m3kg Specific internal energy (u ) in units of kJ/kg Specific enthalpy (h...
C program simple version of blackjack following this design. 1. The basic rules of game A...
C program simple version of blackjack following this design. 1. The basic rules of game A deck of poker cards are used. For simplicity, we have unlimited number of cards, so we can generate a random card without considering which cards have already dealt. The game here is to play as a player against the computer (the dealer). The aim of the game is to accumulate a higher total of points than the dealer’s, but without going over 21. The...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for this game are special oriental dice. Each die has six different patterns. The six possible patterns are: Fish, Shrimp, Crab, Chicken, goldenCoin, Barrel. This game has three dice. In this game, the player can place his or her bet on any die-pattern. The amount of the winning prize is directly proportional to the number of matched dice after the two dice have been tossed...
Overview For this assignment, write a program that uses functions to simulate a game of Craps....
Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the...
For this assignment, write a program that uses functions to simulate a game of Craps. Craps...
For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the player...
Write a modular program to simulate the Game of Life and investigate the patterns produced by...
Write a modular program to simulate the Game of Life and investigate the patterns produced by various initial configurations. Some configurations die off rather rapidly; others repeat after a certain number of generations; others change shape and size and may move across the array; and still others may produce ‘gliders’ that detach themselves from the society and sail off into space! Since the game requires an array of cells that continually expands/shrinks, you would want to use multi-dimensional arrays and...
Write a program in Python to simulate a Craps game: 1. When you bet on the...
Write a program in Python to simulate a Craps game: 1. When you bet on the Pass Line, you win (double your money) if the FIRST roll (a pair of dice) is a 7 or 11, you lose if it is ”craps” (2, 3, or 12). Otherwise, if it is x ∈ {4, 5, 6, 8, 9, 10}, then your point x is established, and you win when that number is rolled again before ’7’ comes up. The game is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT