Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Exclamation String Tokenizer HELP!

    How do I plug the right information in to find regular hours and overtime hours worked of a person for five days? I just don't know what variables and information is to go where. The template is below. Like what would I put in for num1 or avg or grade?

    import java.io.*;
    import java.util.StringTokenizer;

    public class W
    {

    private static FileInputStream inFile;
    private static InputStreamReader inReader;
    private static BufferedReader reader;


    private static StringTokenizer strTkn;


    private static String line,word;
    private static int num1, num2,num3,num4,num5,grade, total;
    private static double avg;

    public static void main (String args[]) throws IOException
    {

    initFile();
    getData();
    calcTotal();
    printResults();

    // Closing data file
    inFile.close();
    }


    // Preparing for input

    public static void initFile() throws IOException
    {
    inFile = new FileInputStream ("C://!!VHSAPCSData\test.txt");
    inReader = new InputStreamReader(inFile);
    reader = new BufferedReader(inReader);
    }




    public static void getData() throws IOException
    {
    line = reader.readLine();
    System.out.println ("data line = " + line );
    System.out.println();

    strTkn = new StringTokenizer(line);


    word = strTkn.nextToken();


    grade = Integer.parseInt(strTkn.nextToken());
    avg = Double.parseDouble(strTkn.nextToken());
    num1 = Integer.parseInt(strTkn.nextToken());
    num2 = Integer.parseInt(strTkn.nextToken());
    num3 = Integer.parseInt(strTkn.nextToken());
    num4 = Integer.parseInt(strTkn.nextToken());
    num5 = Integer.parseInt(strTkn.nextToken());
    }


    public static void calcTotal()
    {
    total = num1 + num2 + num3;
    }



    public static void printResults()
    {
    System.out.println("Separated data line :");
    System.out.println(word);
    System.out.println (grade);
    System.out.println (avg);
    System.out.println(num1);
    System.out.println(num2);
    System.out.println(num3);
    System.out.println(num4);
    System.out.println(num5);

    System.out.println("sum of numbers = " + total);
    }

    }

  2. #2
    karthik pon is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default Re: String Tokenizer HELP!

    Hi,

    my understanding is you are going to give a text file as input strings and going for calculation through the java code. if i am correct, please give me a sample input format also..[1st line is enough...] Thanks.

Similar Threads

  1. String Tokenizer
    By udit ajmera in forum Java Software
    Replies: 0
    Last Post: 03-05-2011, 06:35 PM
  2. Need help with string tokenizer
    By ShortIt in forum New To Java
    Replies: 1
    Last Post: 02-18-2011, 07:04 PM
  3. String Tokenizer
    By sumaih in forum Java Gaming
    Replies: 2
    Last Post: 08-21-2010, 03:23 PM
  4. String Tokenizer
    By hussainian in forum Advanced Java
    Replies: 1
    Last Post: 03-16-2010, 08:58 AM
  5. string tokenizer
    By twinytwo in forum New To Java
    Replies: 2
    Last Post: 03-26-2009, 02:10 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •