Skip to main content
Question Protected by Mast
Commonmark migration
Source Link

Program specification:

For this assignment you will write a program that simulates a rather simplistic Dice Throwing Game. This section specifies the required functionality of the program. Only a text interface is required for this program; however, more marks will be gained for a program that is easy/intuitive to use, with clear information/error messages to the user.

 

The aim of the Dice Throwing Game is to simulate a simple game for 2 players, where they take turn to each roll a dice twice, and score points according to the results of the dice rolls. The winner is the one who accumulates a pre-defined maximum score first. Your program will display a menu which allows the user of the program to select various options to simulate the various operations. Results of all the operations will be printed on the screen as plain text only (eg. “Andy rolled 5 + 3, and scored 8 points”).

 

The “dice rolls” are simulated by the program, using some random number generator. The program will update each player's current score accordingly. For this assignment, the program will only handle TWO players. It will keep track of the current score of the players until one, or both, reaches the pre-defined maximum score, agreed upon at the start of the game.

 

Program Logic:

The Dice Throwing Game begins with a welcome message followed by a menu with the following options :

 

Option (1) asks the 2 players to enter their names. A player’s name must not be blank (or consists of only spaces and nothing else), but may contain spaces between the characters. If this option is chosen again after the players have already been set up, 2 "new" players are set up (ie. with 2 new names, and both their starting scores set to 0). Note that the new players replace the previous players – there are only ever two players at any one time.

 

After the names are set up, the game asks for a maximum score. The default maximum score should be set to 200 points. Each player’s initial score is set to 0.

 

Option (2) simulates the “dice roll” operations for both players. When this option is chosen, the computer generates 4 random numbers between 1-6 (ie. simulating a 6-sided dice), representing 2 dice rolls for each player. It then updates both players' scores accordingly. The scoring rules for each "round" are as follows :

  • if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)
  • if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)
  • if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided
  • a

    if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)

    player is considered a winner if he accumulates a score which is more
  • if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)

    than the pre-defined maximum, and the other player has not reached
  • if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided

    that score
  • a player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score

 

Option (3) shows the players current scores, including who is leading the game.

 

Option (4) displays some brief instructions regarding how to play the game.

 

Option (5) exits the whole program. All player statistics should be cleared.

 

Additional Notes :

The menu must be displayed repeatedly after each operation, until the user chooses Option (5). Inputs other than 1-5 should be rejected, with appropriate error messages printed.

 

If the user chooses Option (2)/(3), before a game has been set up (Option (1)), an appropriate error message should be printed, and the operation aborted.

 

Your program must deal with invalid values entered by the user in a sensible manner.

Program specification:

For this assignment you will write a program that simulates a rather simplistic Dice Throwing Game. This section specifies the required functionality of the program. Only a text interface is required for this program; however, more marks will be gained for a program that is easy/intuitive to use, with clear information/error messages to the user.

 

The aim of the Dice Throwing Game is to simulate a simple game for 2 players, where they take turn to each roll a dice twice, and score points according to the results of the dice rolls. The winner is the one who accumulates a pre-defined maximum score first. Your program will display a menu which allows the user of the program to select various options to simulate the various operations. Results of all the operations will be printed on the screen as plain text only (eg. “Andy rolled 5 + 3, and scored 8 points”).

 

The “dice rolls” are simulated by the program, using some random number generator. The program will update each player's current score accordingly. For this assignment, the program will only handle TWO players. It will keep track of the current score of the players until one, or both, reaches the pre-defined maximum score, agreed upon at the start of the game.

 

Program Logic:

The Dice Throwing Game begins with a welcome message followed by a menu with the following options :

 

Option (1) asks the 2 players to enter their names. A player’s name must not be blank (or consists of only spaces and nothing else), but may contain spaces between the characters. If this option is chosen again after the players have already been set up, 2 "new" players are set up (ie. with 2 new names, and both their starting scores set to 0). Note that the new players replace the previous players – there are only ever two players at any one time.

 

After the names are set up, the game asks for a maximum score. The default maximum score should be set to 200 points. Each player’s initial score is set to 0.

 

Option (2) simulates the “dice roll” operations for both players. When this option is chosen, the computer generates 4 random numbers between 1-6 (ie. simulating a 6-sided dice), representing 2 dice rolls for each player. It then updates both players' scores accordingly. The scoring rules for each "round" are as follows :

  • if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)
  • if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)
  • if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided
  • a player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score
 

Option (3) shows the players current scores, including who is leading the game.

 

Option (4) displays some brief instructions regarding how to play the game.

 

Option (5) exits the whole program. All player statistics should be cleared.

 

Additional Notes :

The menu must be displayed repeatedly after each operation, until the user chooses Option (5). Inputs other than 1-5 should be rejected, with appropriate error messages printed.

 

If the user chooses Option (2)/(3), before a game has been set up (Option (1)), an appropriate error message should be printed, and the operation aborted.

 

Your program must deal with invalid values entered by the user in a sensible manner.

Program specification:

For this assignment you will write a program that simulates a rather simplistic Dice Throwing Game. This section specifies the required functionality of the program. Only a text interface is required for this program; however, more marks will be gained for a program that is easy/intuitive to use, with clear information/error messages to the user.

The aim of the Dice Throwing Game is to simulate a simple game for 2 players, where they take turn to each roll a dice twice, and score points according to the results of the dice rolls. The winner is the one who accumulates a pre-defined maximum score first. Your program will display a menu which allows the user of the program to select various options to simulate the various operations. Results of all the operations will be printed on the screen as plain text only (eg. “Andy rolled 5 + 3, and scored 8 points”).

The “dice rolls” are simulated by the program, using some random number generator. The program will update each player's current score accordingly. For this assignment, the program will only handle TWO players. It will keep track of the current score of the players until one, or both, reaches the pre-defined maximum score, agreed upon at the start of the game.

Program Logic:

The Dice Throwing Game begins with a welcome message followed by a menu with the following options :

Option (1) asks the 2 players to enter their names. A player’s name must not be blank (or consists of only spaces and nothing else), but may contain spaces between the characters. If this option is chosen again after the players have already been set up, 2 "new" players are set up (ie. with 2 new names, and both their starting scores set to 0). Note that the new players replace the previous players – there are only ever two players at any one time.

After the names are set up, the game asks for a maximum score. The default maximum score should be set to 200 points. Each player’s initial score is set to 0.

Option (2) simulates the “dice roll” operations for both players. When this option is chosen, the computer generates 4 random numbers between 1-6 (ie. simulating a 6-sided dice), representing 2 dice rolls for each player. It then updates both players' scores accordingly. The scoring rules for each "round" are as follows :

  • if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)

  • if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)

  • if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided

  • a player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score

Option (3) shows the players current scores, including who is leading the game.

Option (4) displays some brief instructions regarding how to play the game.

Option (5) exits the whole program. All player statistics should be cleared.

Additional Notes :

The menu must be displayed repeatedly after each operation, until the user chooses Option (5). Inputs other than 1-5 should be rejected, with appropriate error messages printed.

If the user chooses Option (2)/(3), before a game has been set up (Option (1)), an appropriate error message should be printed, and the operation aborted.

Your program must deal with invalid values entered by the user in a sensible manner.

Tweeted twitter.com/StackCodeReview/status/722490227378532352
fix indentation copy-paste error
Source Link
Pimgd
  • 22.3k
  • 5
  • 66
  • 144
public class Player {
    private final String name;
    private int totalScore;
    
    Player(String name){
        this.name = name;
    }
    
    String getName(){
        return name;
    }
    
    int getTotalScore(){
        return totalScore;
    }
    
    void setTotalScore(int score){
        totalScore += score;
    } 

}

}

public class Player {
    private final String name;
    private int totalScore;
    
    Player(String name){
        this.name = name;
    }
    
    String getName(){
        return name;
    }
    
    int getTotalScore(){
        return totalScore;
    }
    
    void setTotalScore(int score){
        totalScore += score;
    }

}

public class Player {
    private final String name;
    private int totalScore;
    
    Player(String name){
        this.name = name;
    }
    
    String getName(){
        return name;
    }
    
    int getTotalScore(){
        return totalScore;
    }
    
    void setTotalScore(int score){
        totalScore += score;
    } 

}
deleted 40 characters in body
Source Link
BCdotWEB
  • 11.3k
  • 2
  • 27
  • 45

I'm a first year uni student from Monash Univeristy. We were asked to come up with code that can represent a simple two players dice throwing game (specifications are given below). I

I know as a matter of fact that there are many areas upon which my code could be improved. However, rather than asking other people to correct my code, I would much prefer to be given hints or general principles as to how my code could be improved.I would much prefer to be given hints or general principles as to how my code could be improved. I think I could get more out of this exercise this way. So could someone please provide me with some comments or suggestions? Critics of any level and kind are welcomed! Feel free to pick apart my code! Thanks in advance for any help!

So could someone please provide me with some comments or suggestions? Critics of any level and kind are welcomed! Feel free to pick apart my code!

 if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)

  • if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)

 if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)

  • if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)

 if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided

  • if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided

 a player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score

  • a player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score

I'm a first year uni student from Monash Univeristy. We were asked to come up with code that can represent a simple two players dice throwing game (specifications are given below). I know as a matter of fact that there are many areas upon which my code could be improved. However, rather than asking other people to correct my code, I would much prefer to be given hints or general principles as to how my code could be improved. I think I could get more out of this exercise this way. So could someone please provide me with some comments or suggestions? Critics of any level and kind are welcomed! Feel free to pick apart my code! Thanks in advance for any help!

 if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)

 if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)

 if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided

 a player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score

I'm a first year uni student. We were asked to come up with code that can represent a simple two players dice throwing game (specifications are given below).

I know as a matter of fact that there are many areas upon which my code could be improved. However, rather than asking other people to correct my code, I would much prefer to be given hints or general principles as to how my code could be improved. I think I could get more out of this exercise this way.

So could someone please provide me with some comments or suggestions? Critics of any level and kind are welcomed! Feel free to pick apart my code!

  • if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)
  • if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)
  • if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided
  • a player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score
added 78 characters in body
Source Link
Thor
  • 607
  • 1
  • 9
  • 14
Loading
added 89 characters in body
Source Link
Thor
  • 607
  • 1
  • 9
  • 14
Loading
Source Link
Thor
  • 607
  • 1
  • 9
  • 14
Loading