
-----------------------------------
ast_993
Fri Oct 05, 2012 4:30 pm

Manipulating text from the file
-----------------------------------
The code prints different reports my question is how to print the text from the file in columns of 5 words each per line. The method that supposed to do that, is public void printTokens() but not sure if the loop is properly set up.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.StringTokenizer;


public class WordsManipulationClient {

	
	public static void main(String[] args)
	{
		WordFrequencyService service1 = new WordFrequencyService();
		service1.readPrintText();
		System.out.println();
		service1.storeTokens();
		System.out.println();
		service1.printTokens();
		

	}//end main

}//end WordsManipulationClient



class WordFrequencyService
{
	String[] words = new String [300];      
	int count;


	public void readPrintText()
	{
		
	
		Scanner scan = new Scanner(System.in);
		
		Scanner fileScan;
		boolean validName = false;
		
		
		 do
         {
           
            System.out.print("Enter file name: ");
            String str1 = scan.nextLine(); 
         
            try
            {
            	
               fileScan = new Scanner (new File(str1));
               validName = true;
               
               int lineCount =0;
		
               System.out.println("\tReport1 - Text in Data File");
               System.out.println();
               System.out.println("-------------------------------------------------------");
               while (fileScan.hasNextLine( ))
                   
               {
                 
                  
                  String str = fileScan.nextLine();
                  System.out.println(str);
                  lineCount++;
                 
                  
		       }//end while
               
               System.out.println();
               System.out.println("Number of Lines Read = " + lineCount);
               System.out.println("-------------------------------------------------------");
               fileScan.close();
            }//end try
               
               catch(FileNotFoundException fnfe)
               {
                  System.out.println("Invalid File name; enter again");
               }
         }while(!validName);
		 
	}//end ReadPrintText();
	
	
	public void storeTokens()
	{
		
		Scanner scan = new Scanner(System.in);
		
		Scanner fileScan;
		boolean validName = false;
		
		
		 do
         {
           
            System.out.print("Enter file name: ");
            String str1 = scan.nextLine(); 
         
            try
            {
            	
               fileScan = new Scanner (new File(str1));
               validName = true;
               
               int count = 0;
               
               while(fileScan.hasNext())
               {
            	   
            	   String str = fileScan.nextLine();
            	   StringTokenizer tokens = new StringTokenizer(str,",;.");;
            	   while(count