Brent Geeeee

Greenhorn
+ Follow
since Mar 15, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brent Geeeee

i got a program that stores words and counts the number of occurences of that word and im trying to print them from an arraylist

it just displays Chapter18.CountingOccurences
[Chapter18.WordOccurence@26e431, Chapter18.WordOccurence@14f8dab, Chapter18.WordOccurence@1ddebc3, Chapter18.WordOccurence@a18aa2, Chapter18.WordOccurence@194ca6c, Chapter18.WordOccurence@17590db, Chapter18.WordOccurence@17943a4, Chapter18.WordOccurence@480457, Chapter18.WordOccurence@14fe5c, Chapter18.WordOccurence@47858e, Chapter18.WordOccurence@19134f4, Chapter18.WordOccurence@2bbd86, Chapter18.WordOccurence@1a7bf11, Chapter18.WordOccurence@1f12c4e]

but i want to do it so it displays the word and the count

import java.util.*;

public class CountingOccurences
{
public static void main(String [] args)
{
String text = "Have a good day, Have a good class. " +
"Have a good visit. Have fun!";

Map hashMap = new HashMap();
List arrayList = new ArrayList();

StringTokenizer st = new StringTokenizer(text, " .!?");

while (st.hasMoreTokens())
{
String key = st.nextToken();

if(hashMap.get(key) != null)
{
int value = ((Integer)hashMap.get(key)).intValue();
value++;
hashMap.put(key, new Integer(value));
}
else
{
hashMap.put(key, new Integer(1));
}
arrayList.add(new WordOccurence(key, ((Integer)hashMap.get(key)).intValue()));
}

Collections.sort(arrayList);

System.out.println(arrayList);


}
}

public class WordOccurence implements Comparable
{

String word;
int count = 0;

public int compareTo(Object o)
{
if (this.count == ((WordOccurence)o).count)
{
return 0;
}
else if (this.count > ((WordOccurence)o).count)
{
return 1;
}
else
{
return -1;
}
}

public WordOccurence(String word, int count)
{
this.word = word;
this.count = count;
}
}
[ October 31, 2006: Message edited by: Brent Geeeee ]
17 years ago
hey im doing a program i cant get right,

first im trying to get input and convert it to a double value
im using the JOptionPane.showDialog for the input,

second wat symbol do u use for the square root of or the square of something in an equation?
18 years ago