| | |
Help with Code
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
Hello,
I am an online student in an intro to Java programming course and am a little stuck on my current program. The program is supposed to prompt for the name of files until the user enters "stop" to quit and includes the following methods in addition to the main method:
1. countLines(), which takes a File object, and returns the number of lines of text in the file
2. countLettersInLines(), which takes a File object, and returns an array of integers. In this array of integers, the first entry is the number of letters in the first line of the file, the second entry is the number of letters in the second line of the file, etc.
3. countLetters(), which takes a File object, and returns the number of letters in the file
4. countOneLetter() takes a File object and a letter, and returns the number of occurrences of the specified letter in the file (in uppercase or lowercase). This method and countLetters() can be used to determine the frequency of each letter in a text file.
5. countAllLetters() takes a File object, and returns an array of 26 integers, such that the entries in the array contain the number of occurrences of each letter of the alphabet in the file, disregarding case. The first entry in the array will be the number of a's in the file (regardless of case), the second entry is the number of b's (regardless of case), and so on. This method should use countOneLetter().
6. countIntegers() takes a File object, and returns the number of integers in the file
An example to this program would be:
Please enter the file name, or "stop" to end: short.txt
Number of lines: 2
Line with maximum number of letters: 1
Line 1: 13 letters
Line 2: 5 letters
Number of letters: 18
Frequency of a: 5.555555555555555
Frequency of b: 0.0
Frequency of c: 0.0
Frequency of d: 0.0
Frequency of e: 16.666666666666668
Frequency of f: 0.0
Frequency of g: 0.0
Frequency of h: 5.555555555555555
Frequency of i: 11.11111111111111
Frequency of j: 0.0
Frequency of k: 0.0
Frequency of l: 16.666666666666668
Frequency of m: 11.11111111111111
Frequency of n: 5.555555555555555
Frequency of o: 5.555555555555555
Frequency of q: 0.0
Frequency of r: 0.0
Frequency of s: 11.11111111111111
Frequency of t: 0.0
Frequency of u: 0.0
Frequency of v: 5.555555555555555
Frequency of w: 0.0
Frequency of x: 0.0
Frequency of y: 5.555555555555555
Frequency of z: 0.0
Integers in the file: 2
Please enter the file name, or "stop" to end: stop
Thank you any help will be much appreciated.
I am an online student in an intro to Java programming course and am a little stuck on my current program. The program is supposed to prompt for the name of files until the user enters "stop" to quit and includes the following methods in addition to the main method:
1. countLines(), which takes a File object, and returns the number of lines of text in the file
2. countLettersInLines(), which takes a File object, and returns an array of integers. In this array of integers, the first entry is the number of letters in the first line of the file, the second entry is the number of letters in the second line of the file, etc.
3. countLetters(), which takes a File object, and returns the number of letters in the file
4. countOneLetter() takes a File object and a letter, and returns the number of occurrences of the specified letter in the file (in uppercase or lowercase). This method and countLetters() can be used to determine the frequency of each letter in a text file.
5. countAllLetters() takes a File object, and returns an array of 26 integers, such that the entries in the array contain the number of occurrences of each letter of the alphabet in the file, disregarding case. The first entry in the array will be the number of a's in the file (regardless of case), the second entry is the number of b's (regardless of case), and so on. This method should use countOneLetter().
6. countIntegers() takes a File object, and returns the number of integers in the file
An example to this program would be:
Please enter the file name, or "stop" to end: short.txt
Number of lines: 2
Line with maximum number of letters: 1
Line 1: 13 letters
Line 2: 5 letters
Number of letters: 18
Frequency of a: 5.555555555555555
Frequency of b: 0.0
Frequency of c: 0.0
Frequency of d: 0.0
Frequency of e: 16.666666666666668
Frequency of f: 0.0
Frequency of g: 0.0
Frequency of h: 5.555555555555555
Frequency of i: 11.11111111111111
Frequency of j: 0.0
Frequency of k: 0.0
Frequency of l: 16.666666666666668
Frequency of m: 11.11111111111111
Frequency of n: 5.555555555555555
Frequency of o: 5.555555555555555
Frequency of q: 0.0
Frequency of r: 0.0
Frequency of s: 11.11111111111111
Frequency of t: 0.0
Frequency of u: 0.0
Frequency of v: 5.555555555555555
Frequency of w: 0.0
Frequency of x: 0.0
Frequency of y: 5.555555555555555
Frequency of z: 0.0
Integers in the file: 2
Please enter the file name, or "stop" to end: stop
Thank you any help will be much appreciated.
![]() |
Similar Threads
- Code Snippet: Sample code for taking user input from Shell (Java)
- Code Snippet: code to split (and reconnect) an Access database (part 1) (Visual Basic 4 / 5 / 6)
- Code Snippet: Code that stores and retrieves. (C)
- Code Snippet: Efficient code for extracting unique elements from sorted array. (C)
- Code Snippet: Strings: Looking at ASCII Code (C)
- Code Snippet: Morse Code (C)
- Code Snippet: Gray Code Conversion (C)
- Code Snippet: code to validate data in Access withOUT using messageboxes (Visual Basic 4 / 5 / 6)
- Code Snippet: code to split (and reconnect) an Access database (part 2) (Visual Basic 4 / 5 / 6)
- Code Snippet: Send HTML code to Internet Explorer from basic (Legacy and Other Languages)
Other Threads in the Java Forum
- Previous Thread: Wireless Connection to MySQL
- Next Thread: Graphics Programming
Views: 220 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api apple applet application arguments array arrays automation binary blackberry block bluetooth chat class classes client code component database detection developmenthelp draw eclipse encode error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie number object online oracle os page print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing template test textfields threads time title transfer tree tutorial-sample update windows working





