Question: In Java Please Part 1 : ( Implemented for you ) Pass in the name of the file as input. For example we ll have

In Java Please
Part 1: (Implemented for you)
Pass in the name of the file as input.
For example well have input File1.txt
From there read the content of the File one word at a time using a while loop.
Create a tally called countInt, countFloat, countWord, and countSymbol.
Part 2:
Implement Method 1:
Public static boolean isTokenInt(String token){
}
This method takes a String and determines if its content is an integer
Here is how an integer is defined
(Optional [+ or -] followed by one or more digits [0|1|2|3|4|5|6|7|8|9])
In grammar form
integer ->[sign] digit
sign ->+|-
digit -> number | number [digit]
number ->0|1|2|3|4|5|6|7|8|9
Go through the String token one character at a time and see if it meets the requirement above
Return true if its an integer
Return false otherwise
Implement Method 2:
Public static boolean isTokenFloat(String token){
}
This method takes a String and determines if its content is a float
Here is how a float is defined
(Optional [+ or -] followed by zero or more digits [0|1|2|3|4|5|6|7|8|9]
Followed by [.] followed by one or more digits [0|1|2|3|4|5|6|7|8|9])
In grammar form
float ->[sign][digit].digit
sign ->+|-
digit -> number | number [digit]
number ->0|1|2|3|4|5|6|7|8|9
Go through the String token one character at a time to see if it meets the requirements above.
Return true if its a float
Return false otherwise
Implement Method 3:
Public static boolean isTokenWord(String token){
}
This method takes a String and determines if its content is a word
Here is how a word is defined
(one or more letters [[A-Z]|[a-z]])
Go through the string token one character at a time to see if it meets the requirements above.
Return true if its a string
Return false otherwise
Part 3:
If method 1 returns true increase countInt by 1. If method 2 returns true increase countFloat by 1, if method 3 returns true increase countWord by 1, otherwise increase countSymbol by 1
Part 4: (Implemented for you)
At the end of the while loop print out the following
The file is (filename)
(Filename) contains (countInteger) integers
(Filename) contains (countFloat) floats
(Filename) contains (countWord) words
(Filename) contains (countSymbol) symbols
Part 5: (OPTIONAL FOR 4 EXTRA POINTS)
Enhance Method 3:
Public static boolean isTokenWord(String token){
}
This method takes a String token and determines if its content is a word
Use the following to determine if its a word accounting for grammar symbols
(one or more letters [[A-Z]|[a-z]]) followed by optional (,| : |!|.|?| ;))
Go through the string token one character at a time to see if it meets the requirements above.
Return true if its a string
Return false otherwise

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!