• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help me code PIG  RSS feed

 
Robin Leckey
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to finish this as soon as possible. If anyone would care to help, that would be great. The goal is to get to 50 points before you roll a 1, which sets your score back to zero. This is a single player game unless someone can assist me with making PIG a two player game. I changed it to 25 points to make the game go quicker. By the way, I programmed in Java and used JCreator.
Here's the code:
 
Wesley Grove
Greenhorn
Posts: 13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess first I have to ask, but why are you making this? Here at Java ranch one of the things we try to go by is DoYourOwnHomework. If that isn't what this is for but also realize that here we are NotACodeMill. We'll be glad to guide you, but we're not going to write anything for you past some pseudo code. And the other big issue is that your code is very difficult to read. Something like this needs to be in separate classes and methods, not just main. Your code also gets very far out at places, far past the general 80-120 character limit usually taught. We don't really want to read through something that long especially without, from my cursory glance mind, many comments. Some self commenting methods or pseudo code would greatly increase your chances of getting help, as that way we at least don't have to trudge through however many lines you threw up there.
 
Knute Snortum
Sheriff
Posts: 3556
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have an error on line 20.  You've typed in something that will compile but I know it's not what you want.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12442
42
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is also not written in an OOP way.  All your code is in the main method, wihch is not good style. You may want to read this.

Even for procedural style, there are improvements that can be made. you have a LOT Of code that is repeated...that should suggest you pull it out into a method of its own.
 
Junilu Lacar
Sheriff
Posts: 10879
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, take another look at your incantation for "rolling the dice":

The expression (6-1+1) is equivalent to (6+1-1) which is equivalent to (6 + (1-1)) which is (6 + 0) which is just 6

A better way to do that is this:

If you keep the program the way it is right now where you have a lot of duplicated code, you'd have to change every line that has the same formula. This is the problem with duplicated code. As Fred suggested, you should extract the duplicated code to its own method and replace all the duplicated lines with a call to that method.
 
salvin francis
Bartender
Posts: 1479
21
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aside from what others have pointed out, "performanceTask" is not a good class name for two reasons. First of all, it does not follow Camel case. Secondly, it's not describing what your code is doing.
Follow proper indentations when presenting your code to others.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!