home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
lab14a
letter distributions
arrays
If you have not already checked them off,
we will check off lab13a and lab13b.
We will also watch an educational video on
an educational video about iteration.
Practice: In code pad,
-
Declare an variable of type array-of-String.
(If you don't remember the syntax from yesterday's lecture,
go back an look at it.)
-
Allocate an array of four Strings
BUG:
The Windows version of
BlueJ has a bug when you try to assign a new array to a variable
of type array.
Skip this step and the next two (unless you're on a Mac).
Apologies, on behalf of BlueJ.
-
Inspect this array
(you can evaluate your variable and Code Pad will just tell you
it's a (reference to) n array-of-string (duh); you can then
double-click on the small red square next to that reference value.)
-
Initialize the array to hold
the values to "north", "east", "south", "west",
and inspect your array again.
Here is a screenshot of what things should look like,
except for the bug:
We will consider the letter-frequency example from
lect14b—arrays:
-
Review the lecture note's examples on characters and character codes,
typing in the examples into code pad.
-
Enter the code and run it and
look it over to understand how it works.
-
Modify the code
so that it doesn't care about the case of the letters --
that is, it counts how many times the letter B appears
either as upper- or lower-case.
(This actually simplifies the code a little.)
-
We're about to change the code so that it can process
multiple strings in a row.
In preparation for this, move the process-one-string
code from the constructor to its own method.
Otherwise the class should be have exactly as before.
-
Make a second constructor which takes in any Scanner,
and tallies all characters it can read
You can ignore whitespace.
Test it by evaluating all the characters on this page's html source:
new Scanner( new java.net.URL( "http://www.radford.edu/itec120/2007fall-ibarland/Labs/lab14a.html").openStream() ).
(Of course, you'll also test it using other examples,
like the keyboard or a test-file you create.
Recall lab10b—input: Scanner.)
-
Challenge:
Search engines often want to know what language a page is in.
One way to determine this is to look at that web page's
distribution of letters.
-
Look up letter-distributions for English on the web,
and write a function which tells how close your object's
letter-distribution corresponds to English.
-
Do something similar for two other languages (perhaps Spanish and
German).
Write a method which compares these three scores, and
tells which language it seems closest to.
-
Can you make a list of other language's distributions
(instead of checking exactly three languages)?
We will not be checking this lab off for regular credit;
it is expected that you understand how the array is
used to keep track of the character-tally for each letter.
If we gave a similar problem, you should be able to write it yourself.
If you do want to check off through step #5 (or more) for extra credit,
you can do so in office hours, by the beginning of lab on Dec.05 (Wed).
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs