+ 3
[code-review][java] Acey Ducey
I'm a beginner in Java and want to improve and learn. Therefore I'd appreciate if an intermediate/expert Java developer could look over my code and review it. I'd be grateful for any improvement suggestions or feedback. Thanks in advance. :) This is a game called "Acey Ducey": The dealer shows you two cards. You decide whether you want the dealer to pick a third card or not. If the third card is between the two cards, then you win. Otherwise you lose https://github.com/thadeuszlay/16_acery
2 Respostas
+ 11
Commenting would be helpful xP.
Potential problems:
* If I do not input 'y' my number of cards is still decreased.
* I'm able to input negative numbers as my bet.
* Non-numbers crash the program.
The setMoney method doesn't do anything (It's never called). You could remove it entirely and initialize money in the constructor of the Player class.
The try catch for the Deposit Money doesn't make sense, you're only adding money to the player, and it's already previously going to check if he has enough money to play. The only problem would be the user input amount ie: if it's negative.
Line 55 Main: Replace the 'break' with 'continue'.
The break is what's ending the program. At least the way I see it you shouldn't want to end the program if the player doesn't input the right amount, rather ask for another input again.
Line 36 Main: " Card thirdPick = new Card();"
the value new Card() is never used. You can just write: Card thirdPick;
(Though, If you do this, you may as well place it outside the loop).
Perhaps check out the '\n' escape character. Instead of constantly using one System.out.println right after another, you can use:
System.out.println("____\n"
+ "etc....");
The plus is purely there to show it's on a new line, it could just be written on one line without the plus.
"private static String getUserInput() {
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}"
This is a pretty cool idea, although it relies on the garbage collector pretty heavily. Not that it's bad, just thought I'd put that out there.
ps: It could also be written in one line (optional):
return new Scanner(System.in).nextLine();
Great job though, I had fun playing around with it :P.
Hopefully something I said helps!
0
@Rrestoring faith : thanks man! I also enjoyed implementing it. You are right on so many points! I can't think of ways to thank you other than making your response the best and upvoted it.
If you got time, please also have a look at this:
https://www.sololearn.com/Discuss/363075/code-review-java-grocery-cost-list