Learn Programming in Java

Seaman Word Parse

<<Previous | ToC | Next >>
 
Vivian Killian provided the basic structure of this program, and we are refining her English. Her second line was:
2. Draw dashes (computer displays this)
We know that the number of dashes must match the length of the input word, and mentioned two different ways to do that. From where I'm writing this, I can't see what you did, but did you try one? Are you comfortable with it?

 

Obviously, whatever you have is still only partial, not the whole working program. I have included buttons to see what I wrote for each version, also incomplete, but it gives us some talking points.

Tom's 1word

Here the operative line is line 2, which inputs the whole word, and then line 5, which is just a stub to pick out a single letter (the position of that letter is in variable lx). When I wrote this, I was unsure of whether it would work, so I added line 6 to print out what I know about the program state; my Kitchen computer has no debugger, but it would be preferable to put a breakpoint here and just look. When we implement this program in Java we might leave the debugging print line in until the whole program works, or else take it out before then. In any case, in Java we need to pick out the letters (line 5) and put each letter into an array element. In plain English I might have said:
put letter lx of word into array element lx
or something like that.

After we know how many letters there are, the repeat loop starting line 11 assembles a line of dashes that is printed on line 14. In Java we can also use System.out.print (not println) to do the same thing inside the loop.

Tom's inLetters

In this alternative the word is initialized empty -- that would be your array in Java, but we don't yet know how big to make it so I wrote it in my English as a simple variable -- then as each letter is input, it will be put into the next position of the array instead of my concatenate in line 8. Otherwise, this version is the same as the single word version.

What you should do is bring back your own program so far (the third button down on the right) then (preferably without looking at my code again) modify your program as you see fit to represent how you want to do it, and then turn the page. Don't worry if it doesn't run in the Kitchen computer, that computer has no such thing as arrays. What matters is that it runs in Java, but we aren't there yet.

Five Basic Concepts
Sequence
Iteration
Conditional
Variables
Input/Output

  <<Previous | ToC | Next >>

Revised: 2021 June 3