Results 1 to 2 of 2
Thread: Help Please. use of file reader
- 04-05-2012, 03:24 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 1
- Rep Power
- 0
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).
- 04-05-2012, 06:13 AM #2
Similar Threads
-
java file reader, jgrasp can't find the file
By aramiky818 in forum New To JavaReplies: 3Last Post: 04-22-2011, 02:06 AM -
Excel File Reader
By Subhransu in forum Advanced JavaReplies: 6Last Post: 03-02-2011, 09:30 AM -
Java file reader...?
By prabhurangan in forum New To JavaReplies: 3Last Post: 11-21-2008, 08:19 AM -
[SOLVED] Need help with file reader
By syed.shuvo in forum New To JavaReplies: 6Last Post: 09-27-2008, 07:43 PM -
help with file reader
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 03:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks