Results 1 to 2 of 2
  1. #1
    knes167 is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default Help Please. use of file reader

    Hello. I'm doing a homework assignment where im required to use switch statement and exceptions. II have to turn in three programs that use it in different ways and this is the first. Its compiling find put I get a exception at line 47
    Can anyone point out any errors?




    // Application CountPunct counts punctuation marks in a file
    import java.util.Scanner;
    import java.io.*;
    public class CountPunct
    {
    public static void main(String[] args)
    throws FileNotFoundException
    {
    FileReader file = new FileReader("Punct.dat");
    Scanner inFile = new Scanner(file);
    String line;
    char symbol;
    int periodCt = 0;
    int commaCt = 0;
    int questionCt = 0;
    int colonCt = 0;
    int semicolonCt = 0;
    int count;

    while (inFile.hasNextLine()) // Loop til end of data
    {
    line = inFile.nextLine();
    count = 0;
    while (count < line.length())
    { // Loop til end of line
    symbol = line.charAt(count);
    // TO BE FILLED IN: count punctuation marks with a switch statement
    switch (symbol){
    case 1: symbol='.';
    periodCt = periodCt+1;
    break;
    case 2: symbol=',';
    commaCt = commaCt+1;
    break;
    case 3: symbol='?';
    questionCt = questionCt+1;
    break;
    case 4: symbol=':';
    colonCt = colonCt+1;
    break;
    case 5: symbol=';';
    semicolonCt = semicolonCt+1;
    break;
    case 6: System.out.println("No punctuations found.");
    }
    count++;
    }
    }
    // TO BE FILLED IN: output
    System.out.println("In file "+file+" there are "+periodCt+" period(s).");
    System.out.println("In file "+file+" there are "+commaCt+" comma(s).");
    System.out.println("In file "+file+" there are "+questionCt+" question mark(s).");
    System.out.println("In file "+file+" there are "+colonCt+" colon(s).");
    System.out.println("In file "+file+" there are "+semicolonCt+" semicolon(s).");
    }
    } //END OF PROGRAM
    the output im getting is below:

    In file java.io.FileReader@72766b42 there are 0 period(s).
    In file java.io.FileReader@72766b42 there are 0 comma(s).
    In file java.io.FileReader@72766b42 there are 0 question mark(s).
    In file java.io.FileReader@72766b42 there are 0 colon(s).
    In file java.io.FileReader@72766b42 there are 0 semicolon(s).
    Attached Thumbnails Attached Thumbnails Help Please. use of file reader-lab10-1.png   Help Please. use of file reader-lab10-2.png  

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Help Please. use of file reader

    Quote Originally Posted by knes167 View Post
    java.io.FileReader@72766b42
    This is the output you get when a class does not override the toString method from the Object class. Perhaps you should print the filename instead.

Similar Threads

  1. java file reader, jgrasp can't find the file
    By aramiky818 in forum New To Java
    Replies: 3
    Last Post: 04-22-2011, 02:06 AM
  2. Excel File Reader
    By Subhransu in forum Advanced Java
    Replies: 6
    Last Post: 03-02-2011, 09:30 AM
  3. Java file reader...?
    By prabhurangan in forum New To Java
    Replies: 3
    Last Post: 11-21-2008, 08:19 AM
  4. [SOLVED] Need help with file reader
    By syed.shuvo in forum New To Java
    Replies: 6
    Last Post: 09-27-2008, 07:43 PM
  5. help with file reader
    By jason27131 in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 03:03 AM

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
  •