BrandonA Brown

Greenhorn
+ Follow
since Jan 23, 2016
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by BrandonA Brown

I feel a little embarrassed because I had to put learning Java on the back burner for a few weeks and I plan on picking up where I left off, but yeppers, a lot of community support and advise. Hopefully next week, my days and nights go back to normal. I clicked that link Nigel, but it was a 404 page. When I get back to it, I will read this thread again carefully and try to implement a lot of what was advised and post some more developments.

Thanks guys
3 years ago

saw mon wrote:Dear all;Today I have another question for Using == with Integer.
in this example:
Integer x=400;
Integer y=x;
x++;
Sysout(x==y)
output is false.why?x refrence and y refrence point to same object.if so I think is when increase value in one refrence ;another refrence's value will be increased.



This is the way I learned this:

increment x will result in 401



If you re-assigned after the increment then:

then you would get a true return.

y=x assigns the value of x to y
y==x checks to see if they are equal
Thank you all

So, I only have a little time here and there, but I was excited about re-creating this. Randomly watched some videos and picked up on some new conventions. I have 5 classes and they are all working with each other. I am stopping for the night, but wanted to post what I have so far. This was a big learning venture in that I can start to see how the classes work together. I don't see or haven't benefited from it yet, but it is starting to seep into the logic of it. This took me about 2 hours tonight. I won't be able to spend much time the couple of days, but if you see anything worth commenting on PLEASE do



I took everyone's note to heart although I didn't get into ENUM, for now I am going to stick with List and hard code a lot of it as a learning tool. This is not a working program, it only does the basics, but man - I am super happy with what I have so far

My questions would be: What does 'Packaging' have to do with anything? I assume it is so I can re-use code. I took a snippet of what I think it means. I didn't start a GoFish.java project, just for illustration and attached.

Main:

Card Class

Deck Class

Player Class

Dealer Class
3 years ago

Carey Brown wrote:You're welcome Brandon. Nice job of cleanup. If you do come back to refactor this at some point bear in mind Winston's comments about OO design.
...Regarding 'List':



Thanks for the info, I am java'd out for the night, but thanks to everyone's responses, I am going to use this program as a learning tool. Since this is version 3 of the program

I want to get it back to my first instinct of having at least 4 classes and make them work together. So when I have time, I hope to make this more of an OOP. Many thanks to everyone and tomorrow, I am going to learn a bit more about Lists so I can implement it and see what the benefits and other are going to be.
3 years ago
Thank you so much for the feedback.
Carey -> I still need to learn about Lists. I tried just putting it in there and it broke. Will def be taking a look into it and also thanks for the Collections.shuffle() method. Nice to have that built in. I am not sure what you mean by to many static members. I think i add that keyword in there because that is all I know so far. Static makes it readable by the whole class? or I probably read that wrong.

Chris -> I enrolled to audit a class, thanks for the link. Will let you know how it goes.

Fred -> thanks for the Cow I read several threads on here before registering and one thread someone had mentioned to another to always put code in Code tags, so learned that before posting

Winston -> Yeppers, I don't like the GUI side of programming. I took several classes in Visual Studio and it took away from the coding big time. As for using different classes. this was my third attempt at the program, and originally I had several classes, but I couldn't get them to work together for some reason and I finally got Cards and Deck to work together, but then I couldn't figure out how to deal and assign players cards. The last attempt, just the one class was to get it working. I hope to divide these up into several classes soon. I found an situation where the game broke anyway, so I need to look at closer. It breaks if the last hand before a winner and there is isWar();

Again, just wanted to say thanks and below is the modded code with your suggestions. I will def try to keep up with naming conventions. VB had me under scoring and doing other things. Old habit.
Thanks my new java friends



3 years ago

Carey Brown wrote:Some comments:
'suits' and 'cards' should be in all upper-case because it's a static final, ie a constant.
Too many static members, they should be non-static fields.
Only use under-scores (_) in constant names. Use camel-case for everything else. Eg change Card_Pool to cardPool.
Variable and method names should start with a lower-case. Eg PlayerTwo, and Start_Game.
Methods that check for the presence of something and returns a boolean usually begin with 'is', eg 'isWar' instead of 'Check_For_War'.
Program to interfaces. Eg use List<String> tempDeck = ArrayList<>();
Used Random class instead of Math.random.
Change randNum = (int)(Math.random()*deck.size()); to randNum = rand.nextInt( deck.size() );
Line 161, variable name of 'i' is usually reserved for integers. Perhaps 's' would be better.
Nice indenting.



Thanks for the notes (wow, quicker than I expected).
I haven't gotten to List's yet, but now that I see it for the 'For' loop, i should use 's' instead for string or 'c' for char. thanks. I just read about the Final and all-caps today, didn't change it but I should have, thanks for pointing that out. Will learn about Random soon I hope and will use it from hence forth and much appreciated the comments on variable and method names, I drather use the convention than my own personal tastes. The boolean thing = 100% sound reasoning.
Will learn about List and Random tomorrow and try to update code where needed.

THANK YOU this was educational and will post back tomorrow.

3 years ago
I have searched a few forums and I keep coming back to this one. So this is going to be home for Java, I really like the site. My name is Brandon and I have a little programming knowledge in Visual Basic. I like learning new things and I decided to pick up Java about a month ago. I bought and have been learning from a book called Head First Java. It puts me to sleep (I learn better being hands on and trial and error), but I try to retain as much as I can, and have been supplementing the reading with a Java tutorial series by Derek Banas on YouTube.

I am just now getting ready to learn the GUI part of it but before I get into all of that, I wanted to write a simple card game. I finally completed it after 3 versions (improving on each) but I sat back and looked at it and I am sure it is not OOP.

So my first real semi-program in Java, I was hoping that maybe someone would take the code I have written and give me a hard lesson in Java. It is less than 200 lines of code and only deals with one deck and 2 players. I am learning this on my own as a hobby because I have some ideas I want to implement once I feel I can tackle the job.

I was reading over some of the other beginner posts and I hope I can help on some of those posts. In the meantime, here is the code from my War card game. If anyone wants to give out pointers or show me how to make this OOP that would be great. I kind of feel there should be these classes: Main, Player, Hand and Deck. I am not sure how to make them fit together though.

Thanks in advance and I can't wait to check back tomorrow.

edit: oh, I am not asking for anyone to re-do the program, but if someone felt they wanted to in order to illustrate better what OOP was ... well . I really just need someone that is better than me to give me ideas and thoughts on how to better my own understanding and any bad habits that might be visible from the code below. I rather break those bad habits now than later.




3 years ago