Win a copy of Head First Go this week in the Go forum!

Ansamana Sankarray

Greenhorn
+ Follow
since Nov 22, 2018
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ansamana Sankarray

From module console

Main.java



ConsoleSuperGuess.java

2 weeks ago
MessageGeneratorImpl.java



GameImpl.java

2 weeks ago
I will post some of them here, basically I have 3 modules, 'core' with the game itself, 'console' to play the game from the console, 'web' to do it from the browser, 'web' module is not finished yet.

From module core:

Player.java



ComputerNumberGeneratorImpl.java



2 weeks ago
Hello! I just finished a Spring framework tutorial and I decided to remade that game, just to practice
If anyone could have a look and give any feedback! Would be really appreciated.
Here's a link to the github repository
https://github.com/Ansamana/SuperGuess-2.0

Thanks!
2 weeks ago

wayne brandon wrote:

does it have to captured in another variable?

i tried this:

but it says its ignored




You could instead use method chaining and get it all in 1 statement

1 month ago

Daniel Andersson wrote:Calling methods from another class is confusing to me.
I have this code in one class:


   


The code at line 17 is what I have problems with.



Where MainActivity is the other class. How can I call the method updateCountDownText() without making anything static?



Is the method setMillis static?

I gues that to call the method updateCountDownText you should create an instance of the class MainActivity , new MainActivity().uptdateCountDownText;

1 month ago

Campbell Ritchie wrote:

Ansamana Sankarray wrote:. . . my own solution  . . .

That looks good but you  should be able to use something on the lines of b = !b; to reduce lines 18‑23 to one statement.
What do lines 26‑28 mean?



True
That should work


Lines 26 to 28, adds to an ArrayList the index of all the bulbs on, since the value of i on bulbs.get(i) will never be higher than person, all the indexes stored will never be change again, the name is changed on the code below

1 month ago
I'm not sure if is relevant but I tried to make my own solution just to practice



Prints:
Number of bulbs on is: 10
Index of the bulbs on is[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
1 month ago

Ben Hutchenson wrote:

Ansamana Sankarray wrote:Class MainProgram and Flashcard are not in the same package and you're creating an instance of Flashcard without importing, plus class Flashcard is on the default package and you can't import from the default package.



I updated the three files so the package name matches - two had a lower case F. Just to be clear, now that they're all under the same package there will be no importing of anything required, right?



Yes, no importing is needed if they are in the same package.
I'm new in Java too, I know the feeling of getting stucked
Hope your program works now
1 month ago
Class MainProgram and Flashcard are not in the same package and you're creating an instance of Flashcard without importing, plus class Flashcard is on the default package and you can't import from the default package.
1 month ago
Thanks Salvin Francis and Knute Snortum for your replays!! Really helpful

I will take your suggestions, make modifications and keep them in mind for the future!

About using enums like Salvin said I still don't know how to use them, didn't get to that topic yet.

About using static methods, yes, it was suggested by Eclipse, I'm using notepad++ now.

2 months ago
I made a quick fix on the line 38, as if the player input was 0 it was playing "scissors" instead of printing wrong selection and asking to input a number from 1 to 3 again.

while(playerChoice > 3)

changed to:

while(playerChoice < 1 || playerChoice > 3)
2 months ago
Hello everyone!
I'm still learning basics of Java and I made that game to practice, would appreciate if anyone more experienced could spot me things that I'm doing wrong in there, things that make no sense, bad practices, etc...  Next thing a want to do is a basic GUI using Java Swing. Thanks!!

2 months ago

Paul Folder wrote:Hello,

Some observations in addition to what others have posted:

-Reading the description of GuessAndWin confused me. I thought guessing a number and guessing a finger is two completely separate things and didn't understand the connection and why both are needed. Isn't each player just guessing 2 numbers; an own and a sum?
-All of the methods in GuessAndWin are static at the moment.
-In main(), lines 139-140, two new Player objects are instantiated. Their names are then handed over to playGame(), but there, on lines 33-34 two new Player objects are instantiated again. Consider either handing over the Player objects themselves to playGame(), or instantiating them only in playGame(). Perhaps there will be a use for setters in Player again.
-Some of the printed text could be stored in constants. I see lots of "line breaks" ("-----------------------------------------").

Keep going!



Hello Paul, thanks for your review!

Let's see if I can explain myself:

- Each player is guessing a number from 0 to 10 (the opponent doesn't know your guess) and then play a number of fingers of 1 hand, 0 to 5, the sum of the number of fingers of both players is the result, the player who guessed correctly the result wins.

- Yes, they are static, to call the methods without an object, checking the code again I guess that line 139 "GuessAndWin.playGame(numberOfPlayers, pName1, pName2);" could be change just to "playGame(numberOfPlayers, pName1, pName2);" same with all the "GuessAndWin.printMessages();
 My overall knowledge of programming and Java still poor, I don't know if I'm doing wrong there...

- Lines 129, 130, invokes the constructor Player(String name) to  get the names (p1name and p2name), then lines 23, 24, the constructor Player(String name, int fingersPlayed, int numberGuess) the name is get through p1.getName() and p2.getName() . I did it this way so the names are introduced just once,  number fingers played and number guessed several times until the while loop ends. Again, not sure if this is a good practice

- I will implement the suggestion made by Carey Brown on few posts above, so no more repeated print methods

Thanks!
2 months ago
Thanks for your time reviewing the code Carey, really appreciated.
2 months ago