Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java project

 
john teevan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you help me with this project please can't do it.

For this project you are required to write a program which takes a sentence(i.e. string) as input, and prints out various statistics about the sentence. Sample output for the program will be shown below.

Example

Input sentence:

The first fir$t SP Project sp!


Sentence Statistics

The Number of Valid Words 4
The Longest Word Project
The Shortest Word SP


The words counted by the program should only be valid words i.e. only those containing alphabetic characters.

 
Larry Frissell
Ranch Hand
Posts: 82
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the Scanner class in the API (java.util.Scanner), use to read in each word of the String. That is a start, then you will need to write methods to count the letters etc.
 
john teevan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Larry Frissell wrote:Look at the Scanner class in the API (java.util.Scanner), use to read in each word of the String. That is a start, then you will need to write methods to count the letters etc.


Can you write out the program for me please I am new to this.
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At JavaRanch the motto is "Do your Homework" and "We are not a code mill", see this. Try to take the first step, using the Scanner class to get your string input, insert the words in the array of your choice. If you have problems post the code you have and others will help guide you.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to write, compile and run a java program? That is the first step. Assuming you can do that, write this one in teeny tiny steps. My first go at it would do nothing more than prompt for the input - I.e. print the "Input Sentence:".

once you have it doing that, see if you can actually take in the input.

Once you do that, see if you can figure out how to find the individual words.

Once you do that, try and find the longest word

etc.

Note that at each step, you may have to write some extra code to prove what you did works, and then throw that away later. Once you think you have read in the input, you may want to print it out again to verify you REALLY have captured it. Once you KNOW that works, you can remove the echoing out the input.

If you tackle a problem like this in baby step, it's much easier.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic