• Post Reply Bookmark Topic Watch Topic
  • New Topic

Different operations  RSS feed

 
Jr Morris
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks to everyone who helped me with my question about changing the output. I have another question though. How do I group the different bits of coding for distinct operations together. For example I can have the first bit of coding outputting the 'Hello World' message to screen and then if I wanted to maybe ask a question how do I do that? I have all the distinct coding for each thing but how do I include them in the same programme. Have I got to use the same start and end coding as I did originally or can I simply put a note to myself in the program or can I just start with the code for the next task?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably need to get yourself a good book on programming. Or start with the java tutorials online. Start here and look for the "Getting Started" and "Learning the Java Language" might be a good first two to go through.
 
Jr Morris
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fred, I've just looked at one of the links you gave me. I think that what I was trying to tell you in my own way was that I was trying to develop an application. So for example the first bit of code would output the message to screen of Hello World or something like that. I then wanted the software to ask a question, maybe "What is your name?". I have the code for both of these input and output tasks but how do I group them together in the same "application".
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing some code first, and then figuring out how to put it together is not the best way to create an application.

Generally, you want to start by THINKING. What exactly do you want your program to do? Literally write down everything you want it to do. Break it down into discrete parts. write down the order you want it to do things.

for each of those things, break them down into simpler steps. for example, your high level task may be "quiz the user on mammals". But when you break that down, you see you have to do a bunch of things:

1) have a list of 10 questions - possibly selecting 10 from a collection of 200
2) print the questions to the screen
3) get the user input
4) tell the user if they were right/wrong
5) keep a running tally
6) when done, give them their score as a percentage
7) ask if they want another quiz

Each of THOSE things can be broken down again into smaller steps. you keep revising the steps until a child can understand them all. Only THEN do you start coding.

even then, once you start coding, you do it in teeny, tiny pieces. I never write more than 2-3 meaningful lines of code before I recompile and test. I write a ton of code that I throw away that validates the 'real' code I write. for example, once I write the code to get user input, I will write code to echo it back out, to make sure I'm REALLY getting it, and getting it how I think I need it (i.e. stripping the trailing newline, up-casing it, or whatever).

Make sure you write your pieces as discrete units. for example...it shouldn't matter if i pull the question from a database, a flat file, or I make a webservice call..but once I HAVE the question, I should be able to print it the same way every time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!