Results 1 to 5 of 5
  1. #1
    newguy11 is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default Help needed with reading a text file

    I have to read a text file of names and then give each name a percentage. Then I have to output the names to 2 separate text files, one containing the names who scored higher than 40% and the other containing the names who scored under 40%.
    This is what I have done so far and i have no idea where to go now! Any and all help would be greatly appreciated.

    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class TestResults
    {
        public static void main(String[] args)
        {
            String errs = "";
    
            try
            {
            	Scanner kybd = new Scanner (System.in);
                Scanner inFile = new Scanner(new File("Names.txt"));
    
                System.out.print("\nNames in file: \n");
                
                while (inFile.hasNext())
                {
                    try
                    {
                        String value = inFile.nextLine();
                    
                    System.out.println("Please enter a percentage for " + value + ": ");
                    
                    
                    
                    
                    
                    
                    
                    
                    }
                    catch (InputMismatchException ime)
                    {
                        String valueStr = inFile.next();
                        errs += "\n\t" + valueStr;
                    }
                }
    
                inFile.close();
            }
            catch (IOException ioe)
            {
               System.out.println("ERROR: " + ioe.getMessage());
            }
        }
    }

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Help needed with reading a text file

    Well you need to first take in the percentage, using that Scanner variable kybd.... Use if statements to determine if the percentage entered is less than or above 40
    You will then need a way to write the names to text Files:
    FileWriter (Java Platform SE 6)
    BufferedWriter (Java Platform SE 6)

    This should get you started, take the time to read the docs

  3. #3
    newguy11 is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default Re: Help needed with reading a text file

    Thanks for the help! How would i go about implementing this?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: Help needed with reading a text file

    By reading the docs and trying to write some code based on that?

  5. #5
    karibo is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Replies: 8
    Last Post: 07-17-2011, 03:38 PM
  2. File Reading..Help Needed
    By spartan in forum New To Java
    Replies: 1
    Last Post: 04-26-2011, 03:06 PM
  3. Help reading a text file.
    By Kristoba in forum New To Java
    Replies: 5
    Last Post: 03-11-2010, 09:42 AM
  4. Reading two text file and sum them up
    By matt_well in forum New To Java
    Replies: 36
    Last Post: 07-22-2008, 03:55 AM
  5. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 12:38 AM

Posting Permissions

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