Compsci 100e, Fall 2009, Tagcloud Exercises
The text cloud in the screen shot below is also accessible
via this link where you can browse
the html-source. Questions about the code follow the code listing. The
source for the code is in SimpleCloudMaker.java.
import java.io.*;
public class SimpleCloudMaker {
public static void main(String[] args) throws IOException {
String[] words = { "Computer", "Duke", "Fun", "Interesting",
"Knowledge", "Science", "University", "Work", };
int[] wordClass = { 5, 10, 20, 15, 18, 5, 3, 25 };
CSSMaker css = new CSSMaker();
String header = css.makeHeader();
String footer = css.makeFooter();
File temp = File.createTempFile("tagger", ".html");
FileWriter fileWriter = new FileWriter(temp);
fileWriter.write(header);
for (int k = 0; k < words.length; k++) {
String htm = css.makeHTML(words[k], wordClass[k]);
fileWriter.write(htm);
}
fileWriter.write(footer);
fileWriter.flush();
BareBonesBrowserLaunch.openURL("file://" + temp.getAbsolutePath());
}
}
Questions
- Why are the words in the text cloud:
- in alphabetical order?
- reading left-to-right?
- reading top-to-bottom?
- Why are the words Computer and Science the same
size?
- The word in the biggest font of the text cloud is Work. What
changes should you make in the code so that Fun has the same
emphasis/size as Work (don't change the size of Work)?
- If you add the string Algorithm as the first entry of the
array words and the number 20 as the
first
entry of wordClass a new tag cloud will be
generated with Algorithm appearing with the same size
as Fun. Why does this change work without modifying the rest of the
code?
- What is the point of the declaration FileWriter
fileWriter? Why does that declaration not cause an error? Is it a good idea?
- The class CSSMaker is used to generate
the CSS/HTML that helps create the tag cloud. What are the names of
the three methods called in this class and what type of value does each
method return?
- One class and one exception are made accessible in the program
because of the statement import java.io.*,
what are these?
- The method openURL is a static
method. How can you tell it's a static method and what class is
is the method found in?
- What is the purpose of the call fileWriter.flush()?