File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help creating a tester class in eclipse.

 
nicole poirier
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a two part assignment, I have written the code for the first class but don't know where to start with the second part of the assignment (which is below).

Create a Main class that has the normal main method that you need to start the program. The main method should ask the user for the name of a local input file, and return an error message if it cannot find the file. The input file should be long and varied enough that you can test the Counter methods. Having found the file, your program should create a Counter object with a String parameter that has the contents of the input file. Then you print out the test string along with the various counts, including appropriate labeling of the numbers.

This is the code i have from the first class (if there is any errors in this code please let me know)
 
K. Tsang
Bartender
Pie
Posts: 3222
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nicole poirier wrote:I have a two part assignment, I have written the code for the first class but don't know where to start with the second part of the assignment (which is below).

Create a Main class that has the normal main method that you need to start the program. The main method should ask the user for the name of a local input file, and return an error message if it cannot find the file. The input file should be long and varied enough that you can test the Counter methods. Having found the file, your program should create a Counter object with a String parameter that has the contents of the input file. Then you print out the test string along with the various counts, including appropriate labeling of the numbers.



To get input from the console, you can use Scanner asking for full path to the file. To check the file, there is a java.io.FileNotFoundException you can use. I will let you find out which class to catch that.

Once everything is ok, new Counter(filename)... to do you stuff. Now not knowing what the content of the file can be, I can't tell if your Counter class is doing what you intend to do.
 
nicole poirier
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:
nicole poirier wrote:I have a two part assignment, I have written the code for the first class but don't know where to start with the second part of the assignment (which is below).

Create a Main class that has the normal main method that you need to start the program. The main method should ask the user for the name of a local input file, and return an error message if it cannot find the file. The input file should be long and varied enough that you can test the Counter methods. Having found the file, your program should create a Counter object with a String parameter that has the contents of the input file. Then you print out the test string along with the various counts, including appropriate labeling of the numbers.



To get input from the console, you can use Scanner asking for full path to the file. To check the file, there is a java.io.FileNotFoundException you can use. I will let you find out which class to catch that.

Once everything is ok, new Counter(filename)... to do you stuff. Now not knowing what the content of the file can be, I can't tell if your Counter class is doing what you intend to do.


The rest of the assignment asked for this:

In Eclipse, create a class named Counter that has one String field called text. It has a constructor that sets the one field from a parameter. It also has the following no-parameter methods: getCharCount that returns the number of characters in the text field, excluding '\n' (new line) and '\t' (tab) characters; getWordCount that returns the number of words in the text field, which are sequences of characters separated by new line, tab, space(s), period or comma; and getLineCount that returns the number of lines.

I understand that what you gave me is to say that the file can not be found. But how do you input a local file name and test that file..If that makes sense?
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nicole poirier wrote:But how do you input a local file name and test that file..If that makes sense?

You need to write code that does file I/O. The same tutorial has links to check if the file exists.
 
K. Tsang
Bartender
Pie
Posts: 3222
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my earlier post, I gave you one way to get the user input which is needed in your testing class.

Given your task, and current approach of your Counter class ... it looks to me you will be reading the file 3 times (once per method).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic