• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help on a project Drjava  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// Suto Code
// Have 13 stacks
so below is my code and I have this project due friday and im wondering how to make it where after the loop i write 1 and it restarts the porgram and if i press 999 it exits it i have the varible set and everything


Please help
Thanks










 
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you work on your program logic before you start writing code!
http://www.coderanch.com/how-to/java/StopCoding
Work out the logic perfectly and make sure it works when you run it manually on paper and then start coding.
For example: What if the user enters a number greater than 3 or less than 1 there is no code to handle those situations.
I don't know if this was helpful since I am a beginner myself but I tried to help.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

AR's advice is good: until you have worked out what you want to do, you cannot code it. Most people will find that easier to achieve with pencil and paper.
Also, are you using object‑orientation? I can see no sign of that. And move 99% of the code out of the main method.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
methods are your friends. lots and lots of methods. Each method should do one thing, and do it very well. each should be thoroughly tested before you do anything with it (i.e. use is elsewhere).

Now, a method can call other methods. In fact, a method may do nothing BUT call other methods. That's ok.

So, you may have one method that gets input from the user. You may have a method that figures out what the computer should choose, based on some parameter you pass it - and where you get that parameter from doesn't matter. If i were writing that method, I'd write a ton of code that I eventually delete to test it. Pass it all kinds of values to test it. Then, once I was sure it worked, and I was sure the method that gets input from the user works, I'd call the get-value method, and pass what it returned to the compute method, and get the computer's choice.

This way of approaching the problem also lets you do stuff like this...

you know you want to loop and replay the entire game until the user inputs 999. So I have this pseudo-code:


Then entire program summed up in two lines. I could code this, using a 'stub' for the "play the game" line. I would literally write a loop than runs until the user enters 999. and instead of actually playing the game, have it literally print "i am playing hte game".

Once you have the loop code written and solid, then you change the print method to a playGame() method (possibly with parameters, I don't know yet). Your first draft of the "playGame" method should....print "I am playing the game". Once THAT works, you change it to do things like:

Print "getting User input"
print "computing computer's choice"
print "computing winner"

Once you have tHAT working, you can replace each with a method call that (eventually) does that part.

Writing a program is a lot like using Lego building bricks. You want to have a lot of little pieces/methods that you can snap together into larger and larger programs. The big difference is that (at least for ME and the way my brain works), I start with the large picture, and keep drilling down, breaking things up into smaller and smaller pieces, instead of starting with the tiny pieces and snapping htem together to make the larger 'thing'.

Hope that helps.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!