aspose file tools*
The moose likes Beginning Java and the fly likes New to Java looking for guidance. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New to Java looking for guidance." Watch "New to Java looking for guidance." New topic
Author

New to Java looking for guidance.

Steffen Hogan
Greenhorn

Joined: Jul 20, 2012
Posts: 6
Hello Everyone
First post ever in a Java Forum. I'm learning Java, trying to at least. I read a the Java for dummies book wrote up a blackjack game and now looking to the experts on how to make it better. I wanted to make a working program without any guidance to see if I could do it. Basically its 5000 lines of ifs and a few whiles. Anyways if I wanted to know if I should paste the code, if so where and how and how much of it. Just looking for guidance on what to do next and how to make life easier.
Thank you. -steffHogan
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7779
    
  21

Steffen Hogan wrote:First post ever in a Java Forum. I'm learning Java, trying to at least. I read a the Java for dummies book wrote up a blackjack game and now looking to the experts on how to make it better. I wanted to make a working program without any guidance to see if I could do it. Basically its 5000 lines of ifs and a few whiles. Anyways if I wanted to know if I should paste the code, if so where and how and how much of it.

Welcome Steffen.

First: I don't think anyone's going to look through 5,000 lines of code (or even 500, I hate to say).

Second: If it's mostly 'if's and 'when's, I suspect you have a lot of redundancy (repeated code), and that's what you're going to need to fix.

Third: How many classes does it have? If less than 5, chances are you need to break up the logic into more.

Fourth: How big is your main() method? If more than about 20 lines, again, chances are you need to break down the logic.

Fifth (and probably most important): Does it work?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Steffen Hogan
Greenhorn

Joined: Jul 20, 2012
Posts: 6
Thanks Winston for getting back to me.
Yeah I didn't think anyone wanted to look through the code. Lots and lots of redundancy. Its all in one class and all in the main. It does work though. I'm reading the headfirst java book now and learning more about classes at least getting a better understanding of them. I'm confused about it but okay with it. Its all part of the game right. -steffHogan
Branden Bobo
Greenhorn

Joined: Jul 16, 2012
Posts: 15
First: I don't think anyone's going to look through 5,000 lines of code (or even 500, I hate to say).


While I agree, I am also new to java, but i'm not new to object oriented programming.
If you want to post your code as an attachment, I'll take a look and see if I can help.

also by putting all your code in one method it makes it harder to make changes to, re-use parts of, or extend your code.
From my humble understanding this is one of the key benefits to OOP.

If were that's where would start, by re-factoring your to an OO approach.
Steffen Hogan
Greenhorn

Joined: Jul 20, 2012
Posts: 6
Hey Branden

I think I did the upload right chose the .java file at least. Yeah I'm new to the whole programming thing in general besides a c++ class I took back in high school. I'm going through the coderanch java assignments now trying to get a better understanding of everything. I can see how creating different methods and classes can help out so you can add features with out messing with code that already works. Thanks for replying Branden. -steffHogan
Steffen Hogan
Greenhorn

Joined: Jul 20, 2012
Posts: 6
Server was down first time I tried to upload it and the back button took off the attachment. -steffHogan
-- Second time says .java files are now allowed so threw it in as a .txt
-- Would not let me upload a .txt
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

I can see how creating different methods and classes can help out so you can add features with out messing with code that already works.

you are well on your way. the previous replies are helpful. it took me a long time before i got the hang of OO since i started programming before it was even an idea. i grew to love it though.

most important(well maybe not most important, but important) IMO of the earlier comments is your main method sould do very little. ideally it should look something like this(if it is not a GUI)
public static void main()
{
MyClass myClass = new MyClass();
myClass.doSomething();
}


SCJP
Visit my download page
Steffen Hogan
Greenhorn

Joined: Jul 20, 2012
Posts: 6
Randall,
So the basics that I should shoot for in the main is just bringing all the classes and methods together in a nice small package for the user, right? This is where I would also make this public while the rest are private? -steffHogan
Steffen Hogan
Greenhorn

Joined: Jul 20, 2012
Posts: 6
I feel stupid when it seems like the simple things do not work out.
I'm working on a blackjack game and it works when its all in one class. Now I'm trying to condense the 5000 lines down by putting in classes to get rid of the redundant code. Yet the first class I'm working on the cards dealt is not working I have an array for cards it goes out to 52 (for each card) and a random int to pick a card yet its not returning the card. Not looking for a response just letting out some frustration till I figure it out. - steffHogan
Joseph Potts
Greenhorn

Joined: Jul 21, 2012
Posts: 7
I haven't looked at the code, but by the information you've given, I'd suggest use the switch statement instead of all those if statements, it would considerably make it much easier to read, and (i'm not quite sure about this, but I think it will) shorten the amount of statements with the same output in a better way
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New to Java looking for guidance.