Java Programming

posted by .

Don't know how to start..
Can anyone help me?


For this program you are to create a two class application - a driver and a principal class - that reads in text interactively from the keyboard, and then reports on two aspects of the entered text. First it should print a table of word sizes in the entered text, for sizes from 1 up to 12 and larger; and second, it should report the number of sentences in the text. To be clear on how this should work, here is the text from a sample run:

> run WordProfileDriver
Enter lines of text, type two returns in a row to end

[DrJava Input Box] The time has come, the walrus said - to speak of many things
[DrJava Input Box] At least that's how the ultra-ultra-famous first line goes, from the
[DrJava Input Box]the Lewis Carroll poem! If you don't know it, give it a try.

words of size 1---2
words of size 2---6
words of size 3---9
words of size 4---10
words of size 5---5
words of size 6---3
words of size 7---1
words of size 8---0
words of size 9---0
words of size 10---0
words of size 11---0
words of size >= 12---1
sentences: 2

As you can see, the driver class is called WordProfileDriver (you must use this name). The second class, where all the action happens, must be called WordProfile. Some further thoughts:



Read input using the style of program Backwards from section 7.2 of the iJava textbook.


You must make essential use of arrays in your word size accounting. Notice that words that are of size 12 or larger are lumped together.


You will need to use a StringTokenizer for this problem. In addition to "space", these characters should be considered delimiters: ,.?!:; This means that dash - the symbol "-", and single quote - the symbol " ' ", should be considered characters in a word (and thus "can't" is a single word of length 5, a lone dash is actually a word of size 1, and "head-long" is a single word of length 9).


To count sentences, just count the number of ? (question mark), !(exclamation mark), .(period). Just counting these three sentence terminators is fairly easy, although strictly speaking it's not completely correct, since a sentence might end in ??, for example.


Lines should be read in in the driver, but should be processed using StringTokenizer in WordProfile. Also, the essential array, where where you keep track of word size counts, MUST be in the WordProfile class, and not in the driver.


When you paste in your code, do NOT paste in any import statements. We will import java.util for you, for both classes.



Put your WordProfile class here:

  • Java Programming -

    From what I see in the specifications, it is likely that it is not your first Java course. If you really don't know where to start, you need a good revision before you even start.

    Having said that, here are some hints.

    1. main
    Since you "run WordProfileDriver", you will have your "main" method in the file WordProfileDriver.java which instantiates the WordProfile class, and does the screen IO to store the user input data into a String of the WordProfile object.

    2. WordProfile class

    It will have a String as an instance variable, constructor and get/set methods.
    You will likely to have an append method since input is read in in separate lines. Alternatively you can join the different lines in the main, but that's messy.
    You will need also an "analyse" method to do the calculations. This can be done only when the whole text has been entered, since sentences could be cut between lines.

    The StringTokenizer is an older class that helps in separating a text into "tokens" according to your definition of separators. You could use one set of separators for the words, and another for the sentences, basically run through the text twice. However, this is not a good practice for huge texts of several gigabytes. The approach depends on your level of techniques, namely simplicity versus performance.

    Work on the skeleton, and report back if you need further help.

    Note: do not start a new thread for the same problem in order to provide other teachers and other readers continuity.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. programming.Java language

    Write a program to plot a face. Provide a class FaceViewer and a class FaceComponent.
  2. Computer Science

    Consider the following application files: /JavaCS1/src/guiprojectcity2/DisplayWindow.java import java.awt.*; import javax.swing.*; public class DisplayWindow extends JFrame{ private Container c; public DisplayWindow(){ super("Display"); …
  3. C# Programming

    There are three seating categories at an athletic stadium. For a baseball game, Class A seats cost $15 dollars each, Class B seats cost $12 each, and Class C seats cost $9 each. Create an application that allows the user to enter the …
  4. Java Programming

    I'm new to Java and I'm not sure how to write the source code for this problem I got in class... Write a java program using the while and if statement that will accept ten student grades and that will display the sum of the grades, …
  5. JAVA PROGRAMMING

    Create a java program that will calculate the current grade in a classroom. The program should ask for 5 grades as well as total point value per grade available.
  6. java programming

    Create a java program that will calculate the current grade in a classroom. The program should ask for 5 grades as well as total point value per grade available.
  7. java. please help .

    Write a program that reads a five digit integer number from the keyboard, and then constructs the largest possible integer number with the digits of the entered number. Your program should have only one class , which implements the …
  8. java

    Write a program that reads a five digit integer number from the keyboard, and then constructs the largest possible integer number with the digits of the entered number. Your program should have only one class , which implements the …
  9. java programming

    What is the name of the Java class used to create an object that reads input from the keyboard?
  10. Programming

    Widget company runs a small factory that makes several types of nuts and bolts. They employ (a)1 (b)2 (c)3. Each factory worker can work a maximum of (a)40 hours normal working hours per week. All hours over 40 are paid as over-time …

More Similar Questions