• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help creating a tester class in eclipse.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic