Results 1 to 2 of 2

Thread: Java: Reading information from text files and calculating ...

  1. #1
    Join Date
    Jan 2011
    Beans
    1

    Java: Reading information from text files and calculating ...

    So I need to right a program that reads information from an existing file ("WeeklyPayroll.txt"). The file is exactly this:

    Jane
    Smith
    10.50
    12

    Helen
    Clarke
    11.50
    10

    Rain
    Parker
    10.50
    10

    I then need to take each employee earnings (the this number line in each pragraph) and calculate sepately their total earnings using their weekly hours (the fourth line in each paragraph). How do I take specific lines from a file? Here's a program i have that simply reads the file and re-prints it. Can someone help me?

    import java.io.*;

    class txtFile
    {
    publicstaticvoid main(String[] args) throws IOException
    {
    FileInputStream file = new FileInputStream("WeeklyPayroll.txt");
    InputStreamReader isr = new InputStreamReader(file);
    BufferedReader reader = new BufferedReader(isr);

    int ch;

    while ((ch = reader.read()) != -1)
    {
    System.out.print((char)ch);
    }
    isr.close();
    file.close();
    }
    }

  2. #2
    Join Date
    Jun 2010
    Location
    asoko
    Beans
    834
    Distro
    Ubuntu

    Re: Java: Reading information from text files and calculating ...

    instead of reading char by char with bufferedreader.read(), try bufferedReader.ReadLine()
    and use println(string) rather than print(char).
    will make your job much easier.

    thats all the advise i can give on homework, otther than to use code tags when posting code, so your indents don;t get all messed up.

Tags for this Thread

Bookmarks

Posting Permissions

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