Program doesn't work as expected for now
Program doesn't work as expected for now
Could you be more specific about what is not working? What happens vs. what do you expect to happen?
1) The class is called "AbstractPlayer", but it is not declared abstract (in fact, it's instantiated it in Main). It's recommended you either rename it to Player, or make it an abstract class and then have a Player class that extends it (the word abstract has a specific meaning in Java)
2) Inside the game logic, you don't want to be hardcoding things like the names of the players. It's a good idea (and specified by the requirements) to make it easily extensible to support 4 players. If you have to go an add if statements checking player names in order to add new players, then the code isn't extensible.
3) What is the GameLogic's keepScore method trying to accomplish? Is the purpose of this method to simulate one of the players scoring a point? If so, how do you know which player scored the point (is it supposed to be random?) And what is the purpose behind returning the 0th index of the Array every time? That seems to imply that the game would only ever be at 0-0.
4) What is the purpose of taking in "playerScore" in the constructor of an AbstractPlayer? Wouldn't all players start at 0-0 or is there a case where someone would start with more points?
5) In your Main, I recommend creating the players as variables, rather than inline with the keepScore method. This would allow you to call keepScore multiple times on the same player.
6) The name of the keepScore method doesn't really explain to me what it's trying to do. Is this called when a Player scores a point? If so, maybe scorePoint would be a better method name.
7) One concept that I feel is missing from the overall design is the concept of the Game itself. A Game contains multiple players, and has a state (such as in progress, player 1 won, player 2 won) right? How will you represent that logic in the current design? Maybe the GameLogic can handle that, but it doesn't right now. If there can be 4 players, does it make sense to also have a representation for a Team of players?
8) Minor issue: the naming of constant variables should be all upper case: GAME_SCORE_CHOICE (is there a more descriptive name for this variable?)
9) What is this syntax? Line 67-69
10) How are you implementing the mode/view/controller pattern?
11) Especially since unit tests are a requirement: try writing tests along with or before writing the code if possible. Describe the desired behavior of your project in plain English sentences and then try converting those into JUnit test cases. Tests are often considered something that is done after the implementation, but it doesn't have to be that way. Used correctly, unit tests can be a tool to help you write code. I think we're all guilty to some extent of looking at unit tests as a hassle, but if you get in the mindset of using unit tests to help you, they don't have to be that way.
1. There is no such score as "Love 10" in tennis.
2. I didn't see anything in the requirements related to scoring of a set and yet you have "set" as one of your scores
3. I don't understand what that keepScore() method is supposed to be doing and hardcoding "bob" and "joe" in that method is definitely wrong.
4. Where are the unit tests?
5. How is MVC implemented here?
No, it's "Love", "15", "30", "40", "Deuce", "Advantage", "Game", "Set"Lg Long wrote:. . .
. . . "Love", "10", "15", "30", "40", "Deuce", "Advantage", "Game", "Set" . . .1. There is no such score as "Love 10" in tennis.
That doesn't look right at first sight, I am afraid. Please explain more.Lg Long wrote:. . . . I think it might be pseudo code:
do{
if(player == score[0]){
player == '10';
} . . .
That doesn't look right at first sight, I am afraid. Please explain more.
Lg Long wrote:
4. Where are the unit tests?
Good question, I will be writting the unit tests after I figure out my logic
I am implementing the MVC by having a Model - ClassPlayer(pojo), Controller - GameLogic(state-behaviour of the player-game), View - Interface(scanner class); EntryPoint - Main
I can see two problems in that toString() method.
1: You are still calling the class AbstractXXX.
2: You are recording both players' scores twice.
Shouldn't the displayed order of scores change depending on who's serving?
Lg Long wrote:This is weird. How do I delete a post, if I post something by mistake?
All things are lawful, but not all things are profitable.
Lg Long wrote:I need to build a method to:
- assign index value to a player.
- check for 'deuce, advantage, deuce'
- print result
How can I split all that in different methods. To write tests more easily?
I wrote:Because you're writing your tests after the design, your design will most likely already be difficult or impossible to test at a unit level.
Junilu Lacar wrote:Coming back to refactoring and that first sketch or experiment I showed. I would look at that and ask myself "Do I even need a Player class right now? What exactly does a Player do anyway besides provide its name? What if I only do this instead?" Then I'd try another experiment, simplifying the code:
That certainly is simpler. Maybe I'd try implementing this instead.
Campbell Ritchie wrote:A player isn't a String. You have a player class; use it.
The scores aren't Strings. Nor are they ints. Something is only an int if you can do arithmetic with it. They might however be elements of an enum.
Lg Long wrote:I dd solve the test and I might have an idea of how to build separate methods for points to be added separate, in this way it is easily testable.
This is my code ...
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
You are in a bit of a quandary there; you need to learn how arrays work, even though you know your app would be better if you use enums (not Enums). You will have that difficulty sometimes, not knowing whether to use the best solution or to try out a particular language feature.Lg Long wrote:. . . Thank you for the comment, planning to use Enums as I move up the ladder, for now i want to do exercises with arrays. . . .
I thought that whenever there is a number, they did use the term “all”. “Love‑all”, “15‑all”, “30‑all”, and “deuce” are valid scores. The board might however display that as “30‑30” etc.Piet Souris wrote:. . . there is no use of words like 'all' or 'deuce' . . .
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|