File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help creating a tester class in eclipse. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help creating a tester class in eclipse." Watch "Help creating a tester class in eclipse." New topic
Author

Help creating a tester class in eclipse.

nicole poirier
Greenhorn

Joined: Apr 03, 2013
Posts: 6
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

Joined: Sep 13, 2007
Posts: 2362
    
    7

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.

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
nicole poirier
Greenhorn

Joined: Apr 03, 2013
Posts: 6
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

Joined: Jun 06, 2007
Posts: 2716
    
    6

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.

SCJP, SCWCD.
|Asking Good Questions|
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2362
    
    7

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).
 
Don't get me started about those stupid light bulbs.
 
subject: Help creating a tester class in eclipse.