• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Madlibs Program  RSS feed

 
Matrica Kovolunchy
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am trying to create a java program that will do madlibs. This program must, take in a file through a command line argument, find "variables within a written text, then rewrite the file and save it as an output. I know that was wordy, so let me demonstrate.

Say I have a text file called input.txt and within it lies:
I once was a crazy [adjective] and [decision] to
divide [number] by 0.

If I call java lala input.txt output.txt

The program must take the input file (input.txt) and list "adjective", "decision" and "number", ask for an input. Then the program must rewrite the text with the inputs a user gave it and store it in output.txt.

I am trying to write accurate pseudocode before I actually start programming. How does this look?

Read the values of the arguments and store them as two variables.
If there are more than two arguments in the argument line throw an error and quit the program
Read the text from the file defined in command line argument 0
Put the values "defined" between [ ] into an arraylist and end the read when there are no more lines left <----How would I go about this?
Use a loop to store values into the respective indexes of the arraylist where the values are defined and end the loop when done with values.
Reprint the input text file with the values in the arraylist and save it to the value defined in command line arg 1 <----Don't know how to go about this.

Sorry for the long post, but I thought it would be worth explaining. Thank you for your time!



 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java I/O tutorial is probably a good place to start learning about reading from and writing to files.
Personally I'd swap the first two steps around. That way you can also check that there aren't less than two arguments. If there were and you tried to assign the values to variables you would get an exception. Apart from that it looks like a good approach.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matrica Kovolunchy wrote:I am trying to write accurate pseudocode before I actually start programming. How does this look?

As Stuart said: Looks like a good start; and it's great to see that you're doing it (hence the +1 on your post).

One thing: You haven't said which order you prompt for the input (ie, in the order they appear, or by type of word), and whether there is anything different about the prompt for an 'adjective' and the prompt for a 'decision'.
Just because you're writing pseudo-code doesn't mean that you can afford to be "woolly" about these things.

Writing good pseudo-code is a bit of a black art, and I know many experienced programmers (myself included) to whom it doesn't come naturally; but the mere fact that you're starting now is a great sign.

Keep it up.

Winston
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen her design something else; she is good at it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!