[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Isaac Durá wrote:Any idea, please?
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I trust that means you only have one class with ROCK PAPER and SCISSORS in.Isaac Durá wrote:I have refactor the code, creating a class only for the enum . . .
Isaac Durá wrote:What I would need is convert this [...] into a String, not the contrary.
It is a bad name I put for test...
When I put [...] outside the brackets of the main class, but Netbeans ask me for change the name of the file.
you have the bad habit of not following up on your questions with your final result. That gives us no way to comment on your result and identify areas that can still be improved.
You should develop the good habit of making sure to read all replies. Creating many threads makes it harder for you to keep track of replies, which is another reason why we discourage multiple threads.Isaac Durá wrote:. . . I hadnt seen the post, till now. . . .
Junilu Lacar wrote:If you're wondering why I use the term "conversation" to describe what's happening in the code, here's how I think of the code...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
What's the difference between a PlayerA object and a PlayerB object in the context of a Rock-Paper-Scissors game?
Winston Gutkowski wrote:
I hate to say, but 'ties()' seems redundant to me. All you need is:[code]...
if (player.beats(computer)) {
// whatever
} else if (computer.beats(player)) {
// whatever
} else { // the result must be ...
Test it by all means, but you won't find what it wrong with it. You should have a method which adds points to the current score. Much more useful than a set method. It also means you can, as Winston Gutkowski often says, “tell, don't ask.”
During the design process, these are the kinds of questions I ask:
1. Who should be responsible for determining a tie between two moves?
2. Who should be responsible for determining a win?
3. Who should ask for a player's move?
4. Who should convert the console input into a Move object?
5. Who should ...
Didn't you understand what I said last week about tell, don't ask?
Why are you using Strings for equality when you already have enum constants; even the Java® Language Specification says you can use the == operator.
Why do you have points A and B in the same class? Why two fields? You could have two people playing and set each with different scores for each other.
No. I meant in line‑91, but the code you quoted in that method is no better. The whole idea of an enumerated type is that you use an enumerated type. You do not try to convert it to Strings or anything like that. You can do everything with the enum constants, including equality and switch‑case.Isaac Durá wrote:. . . Where here: