silentcreeper 0 Newbie Poster

Here is what i have now ... i fixed the problem where i was losing words ... now all i have left to do is sort my array from occurs most often to occurs least often with the words with the same number of occurences in alphabetical order .... if i can get that i will be done.

here's my code

[B]import[/B] javax.swing.JOptionPane;
[B]import[/B] javax.swing.JFileChooser;
[B]import[/B] java.util.Scanner;
[B]import[/B] java.util.StringTokenizer;
[B]import[/B] java.io.*;
 
[B]public[/B][B]class[/B] Assn2_5jnv {
 
[B]public[/B] [B]static[/B] String bigAssStringMaker (Scanner txtFile){
 
String bigAssString = [B]new[/B] String();
txtFile.radix();
 
[B]while[/B](txtFile.hasNextLine()){
bigAssString = bigAssString + txtFile.nextLine();
}
 
[B]return[/B](bigAssString);
}
 
[B]public[/B] [B]static[/B] [B]int[/B] wordCount (Scanner fileText){
 
String bigString;
[B]int[/B] count = 0;
 
 
bigString = [I]bigAssStringMaker[/I](fileText);
 
StringTokenizer temp = [B]new[/B] StringTokenizer(bigString, " 0123456789,.;:–-!$?()[]&#\'\"\t\n");
 
[B]while[/B](temp.hasMoreTokens()){
 
count++;
temp.nextToken();
 
}
 
[B]return[/B](count);
 
}
 
[B]public[/B] [B]static[/B] [B]void[/B] fileToArray (Scanner textFile, String[] importString){
 
[B]int[/B] k = 0;
String largeString;
 
largeString = [I]bigAssStringMaker[/I](textFile);
 
StringTokenizer toke = [B]new[/B] StringTokenizer(largeString, " 0123456789,.;:–-!$?()[]&#\'\"\t\n");
 
[B]while[/B](toke.hasMoreTokens()){
 
importString[k] = toke.nextToken();
k++;
 
}
 
}
 
[B]public[/B] [B]static[/B] [B]void[/B] sortArray(String[] alphabeticalArray){
 
[B]int[/B] index, indexOfNextSmallest;
[B]int[/B] numberUsed = alphabeticalArray.length;
 
[B]for[/B](index = 0; index < numberUsed; index++){
 
indexOfNextSmallest = [I]indexOfSmallest[/I](index, alphabeticalArray, numberUsed);
[I]interchange[/I](index, indexOfNextSmallest, alphabeticalArray);
 
}
 
}
 
[B]public[/B] [B]static[/B] [B]int[/B] indexOfSmallest([B]int[/B] startIndex, String[] speechArray, [B]int[/B] numberUsed){
 
String min = speechArray[startIndex];
[B]int[/B] indexOfMin = startIndex;
[B]int[/B] index;
 
[B]for[/B](index = startIndex + 1; index < numberUsed; index++){
[B]if[/B](speechArray[index].compareToIgnoreCase(min)<0){
 
min = speechArray[index];
indexOfMin = index;
//min s the smallest of speechAray[startIndex] through speechArray[index]
 
}
}
 
[B]return[/B](indexOfMin);
 
}
 
[B]public[/B] [B]static[/B] [B]void[/B] interchange([B]int[/B] i, [B]int[/B] j, String[] array){
 
String temp = [B]null[/B];
temp = array[I];[/I]
[i]array[I] = …
silentcreeper 0 Newbie Poster

What are the errors you are recieving if any, or is it just not doing what you want it to do.

Its just not doing what i want it to do.

When i am creating the array of all unique words it loses the very last word and i dont know how to fix that.

And i also dont know how to sort the last array properly ... i can put it in order from occurs most often to occurs least but i cant get the words that occur the same amount of times in alphabetical order.

I am just really lost and stuck ... my assignment is due at 7 pm tonight so in less than 6 hours ... if you can maybe possibly just fix my progam to do what the assignment asks and send it back to me because i have no idea how to do it.

thanks

silentcreeper 0 Newbie Poster

ok I poseted about an assignment that i had to do for my Java programming class. Now i have attempted it and i have kind of gotten it to work but its not working properly ... i have no idea what i'm doing wrong ... please help me fix my program.

Here is what it is supposed to do:


Your program must:

  • Not declare any class attributes. You will not need them in a carefully designed class.
  • Read a single speech text file into an array of words, and then print to the screen the total number of words found in the file. For example, the Fort Bragg speech contains 3654 words.
  • Display to the screen the number of unique words as well as the percentage of unique words to total words. For example, the Fort Bragg speech contains 995 unique words, representing 27% of the total.
  • Prompt the user for any word, and then display the number of occurrences of that word in the speech.
  • Output a text file that consists of a listing of the unique words in the speech with the number of occurrences of each word following the word. The file lists the words starting with those occurring most often and ending with those occurring once only. If you have words that occur the same number of times list them in alphabetical order.

Here is what i have done so far

import javax.swing.JOptionPane;
import javax.swing.JFileChooser;
import java.util.Scanner;
import …
silentcreeper 0 Newbie Poster

Class attributes are attributes declared within the class but outside of all your methods ... for some reason my teacher doesnt want us to use these. I'm not sure yet if this is going to significantly complicate things ... I dont think it will make that much of a difference.

Thanks for the link ... i will look over that and see what i can do then i will ask again if i get stuck

silentcreeper 0 Newbie Poster

Hi, I have been working on a project for my java programming class but I just dont know where to even start.

here is what i was assigned


Your program must:

  • Not declare any class attributes. You will not need them in a carefully designed class.
  • Read a single speech text file into an array of words, and then print to the screen the total number of words found in the file. For example, the Fort Bragg speech contains 3654 words.
  • Display to the screen the number of unique words as well as the percentage of unique words to total words. For example, the Fort Bragg speech contains 995 unique words, representing 27% of the total.
  • Prompt the user for any word, and then display the number of occurrences of that word in the speech.
  • Output a text file that consists of a listing of the unique words in the speech with the number of occurrences of each word following the word. The file lists the words starting with those occurring most often and ending with those occurring once only. If you have words that occur the same number of times list them in alphabetical order.

I'm not asking anyone to do my whole project ... i just need some help getting started.

For example i dont know how to read or write text files and i am not sure how to manipulate arrays of strings.

Any help would be greatly …