• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help find the solution to my problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I really don't know how to make my program work, I just begun Java and I feel completely clueless. I tried to create a program that outputs  a randomly generated paragraph from a selection of arrays but I don't know how  to finish off the program. I'm sorry.

 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using Applet? Applet has been deprecated since version 9.

You only need one instance of Random. You could make it a private static final Random just inside the class declaration.

Your various arrays for parts of speech should also be make private static final, i.e. as constants.

Your indentation needs a lot of clean up.

You are always choosing the range of the random number based on the SubjectForSentence.length. Where you are using the array applies to arrays of differing lengths.

You are creating a String array for StoreSentences but initializing it to a length of zero.

You need to create some more methods because the body of Paragraph() is way too big.  And method names should begin with a lower case character, so, paragraph().

How about
And,
Where you build the sentence string you add in a bunch of "". That's an empty string and serves no purpose they way you've used it.
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch Mark.

Can you please tell us what the code should do and what the code does? If there are any error messages please include them.
You have a number of lines of code, did you make this all yourself or did you get this from a book or a web site?
If you got this code from some other place then please let us know to help avoid copyright laws and so that we can see the code in full context.
Your code formatting seems a little off and most IDEs will fix this for you so that it's easier to read.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've got an inner class called Sentence. Its only purpose is to hold the various parts of speech. I think you'll find that as you clean this up these can all be local variables to your paragraph() method.

Get rid of your class Print.

Your main() should look like

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, Ms.Father went on a road. Then, Teacher ran
over a pen. Next, Car went by an integer. Almost
Alexander Hamiltion walked near an octopus.
Lastly, Jimmy went over a binder.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CONSTANTS:

Constants  don't ever change. There's only ever one of them.

In Java a constant is declared and initialized just inside the class declaration. They must be "static final" and are usually "private", though occasionally they're "public" if code outside of the class needs access to them.

There is a particular naming convention in Java for constants. The name of the constant should be entirely in uppercase with words separated by underscores (_).

Some data types should be created as a constant. Creating a Random object is one of them. There only ever needs to be one instance. A Scanner created from System.in is another example. You only ever want one of these because if you create multiple instances they can walk on each others data.

So for you, your class might define these constants.
reply
    Bookmark Topic Watch Topic
  • New Topic