Campbell Ritchie wrote:Expunge the word “float” from your vocabulary. [At least whilst programming.]
Why have you got so many instances of the keyword static?
Divide your task into smaller parts. You need to read from the file before you do anything else, so show us reading on its own. Don't mix reading and anything else. Do the other tasks, like counting words and sentences (which I think you are doing wrongly) later.
salvin francis wrote:Why is your class called "Main" ? Reading the name of this class does not tell me what it does .
Also you have a lot of code in your main method <-- It's a link
In which case a float will be worse. You are getting wrong values because you aren't counting or calculating correctly.Kelvin Okornoe wrote:. . . double gives me wrong value/computation . . .
Campbell Ritchie wrote:
In which case a float will be worse. You are getting wrong values because you aren't counting or calculating correctly.Kelvin Okornoe wrote:. . . double gives me wrong value/computation . . .
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:What does this line in your opening post mean:
Notice, that the text can contain multiple lines, not just a single line like in the previous stages. You should analyze all the lines.
If the file is:
I was reading a
book. But when
I got sleepy, I
went to bed.
do we have two sentences?
There are three kinds of actuaries: those who can count, and those who can't.
Campbell Ritchie wrote:Afraid I don't like the technique of getting rid of all the spaces. There must be a simpler way to count sentences than that. Much simpler.
Similarly I don't like that way of counting printing characters. The definition of line end characters given in your first post is incorrect, and won't work on a Windows® machine.
Liutauras Vilda wrote:How many you got?
Liutauras Vilda wrote:@OP
Run through your sentences counting this nonsensical: "Done! A boy with toy. Really? Yes... Oh boy!"
I counted 5 sentences. How many you got?
Yes...
Kelvin Okornoe wrote:Current Implementation
Liutauras Vilda wrote:
This bit. String has length() method. So perhaps you don't need to convert to char array too.
Liutauras Vilda wrote:
Kelvin Okornoe wrote:Current Implementation
As Campbell asked, what do you achieve by removing all the spaces before counting sentences? Perhaps trim() would be enough?
Liutauras Vilda wrote:1. coderanch is a forum! Cozy one.
2. coderanchisaforum!Cozyone.
When you split by ! you get array with elements:
1. [coderanch is a forum] [Cozy one.]
2. [coderanchisaforum] [Cozyone.]
So what do you achieve by removing all the spaces?
Only the first and last spaces might affect the result, so really trim() (removes leading and trailing spaces) might be the wise thing to do right after reading the file.
Kelvin Okornoe wrote:Am I allowed to reference the code from github? So I don't keep re-posting the code here.
Liutauras Vilda wrote:
Kelvin Okornoe wrote:Am I allowed to reference the code from github? So I don't keep re-posting the code here.
You are, just not all people will be interested to click on the link and go "somewhere". And to keep discussion and the tangible asset on the forum might be useful for future readers, while your Git repository technically can get demolished at any given point in time.
Liutauras Vilda wrote:For the moment let's assume your calculations are correct.
Do you think would be better if you'd create a class similar reading to TextStatistics, to which you could pass potentially a text or file and be able to:
TextStatistics myFavouriteBook = new TextStatistics(text);
or
Afraid not. It would take too long to find the current version, and some people are reluctant to go to outside links.Kelvin Okornoe wrote:Am I allowed to reference the code from github? So I don't keep re-posting the code here.
Campbell Ritchie wrote:Expunge the word “float” from your vocabulary. [At least whilst programming.]
Why have you got so many instances of the keyword static?
Divide your task into smaller parts. You need to read from the file before you do anything else, so show us reading on its own. Don't mix reading and anything else. Do the other tasks, like counting words and sentences (which I think you are doing wrongly) later.
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|