Skip to content

Commit 1b45938

Browse files
authored
Merge pull request #243 from habibasorour/issue_239_listing
Issue 239 fixed: 3.6 listing added
2 parents cfd3457 + 28a5002 commit 1b45938

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

source/ch3_javadatatypes.ptx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,11 @@ public class HistoArray {
830830
</p>
831831

832832
<p>
833-
Lets stay with a simple frequency counting example, only this time we will count the frequency of words in a document. A simple Python program for this job could look like this:
833+
Lets stay with a simple frequency counting example, only this time we will count the frequency of words in a document. <xref ref="python-word-count" text="type-global"/> shows a simple Python program for how this could look.
834834
</p>
835835

836-
837-
<program xml:id="python-input-file2" interactive="activecode" language="python">
836+
<listing xml:id="python-word-count">
837+
<program interactive="activecode" language="python">
838838
<code>
839839
def main():
840840
""" Program to read a file and count the frequency of words in the file. """
@@ -850,11 +850,14 @@ def main():
850850
main()
851851
</code> <tests> </tests>
852852
</program>
853+
</listing>
853854

854855
<p>
855-
This program reads the file <c>alice30.txt</c> (which follows), and it then splits it into a list of words. Next it creates a dictionary called <c>count</c> which maps each word to the number of times that word occurs in the text. Finally, it prints out the words in alphabetical order along with their frequency.
856+
This program reads the file <c>alice30.txt</c> in <xref ref="datafile-alice1" text="type-global"/>, and it then splits it into a list of words. Next it creates a dictionary called <c>count</c> which maps each word to the number of times that word occurs in the text. Finally, it prints out the words in alphabetical order along with their frequency.
856857
</p>
857858

859+
<data xml:id="datafile-alice1">
860+
<title>Data file for testing the word frequency program</title>
858861
<datafile label="datafile-alice1" filename="alice30.txt" editable="no" cols="30" rows="15">
859862
<pre>
860863
Down, down, down. Would the fall NEVER
@@ -877,12 +880,13 @@ main()
877880
nice grand words to say.)
878881
</pre>
879882
</datafile>
883+
</data>
880884
<p>
881-
Notice that the structure of the program is very similar to the numeric histogram program.
885+
Notice that the structure of <xref ref="java-word-count" text="type-global"/> is very similar to the numeric histogram program.
882886
</p>
883887

884-
885-
<program xml:id="java-use-input-file" interactive="activecode" language="java" datafile="alice30.txt">
888+
<listing xml:id="java-word-count">
889+
<program interactive="activecode" language="java" datafile="alice30.txt">
886890
<code>
887891
import java.util.Scanner;
888892
import java.util.ArrayList; // import the ArrayList class to use dynamic arrays
@@ -923,9 +927,10 @@ public class HistoMap {
923927
}
924928
</code> <tests> </tests>
925929
</program>
930+
</listing>
926931

927932
<p>
928-
Improve the program above to remove the punctuation.
933+
Improve <xref ref="java-word-count" text="type-global"/> to remove the punctuation.
929934
</p>
930935
</section>
931936

0 commit comments

Comments
 (0)