• Post Reply Bookmark Topic Watch Topic
  • New Topic

Another ShoutBox Question  RSS feed

 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy folks,

I have created a Shoutbox class without a Main argument because I am going to call it into my Virtual World and run it there.  The Shoutbox creates a canned shout out and a random shout out.  I know the canned shout out works.  I'm not so sure about the random.  I know I am building random strings but I am stuck on the output.  Any advice?

 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  I am stuck on the output.

Please explain what the problem is.
Post the current output,  add some comments saying what is wrong with it and show what you want the output to  be.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
  I am stuck on the output.

Please explain what the problem is.
Post the current output,  add some comments saying what is wrong with it and show what you want the output to  be.


I apologize for not qualifying my question-I hit submit too quick.  What I am hoping to generate is a completely random sentence that could make sense or be completely imbecilic.  Maybe do something like this:



But I've already returned "builder".  Could I do this:



I'd need to instantiate randomBuilder first, right?

 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could I do this: 

Did you try it?
What happened?
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
Could I do this: 

Did you try it?
What happened?


I guess I don't know how to instantiate as well as I thought.  Getting an unreachable statement.



So, no, it didn't work.  And yes, I am an idiot.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting an unreachable statement. 

Please post the full text of the error message showing Where  the unreachable statement is.  For example:
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
Getting an unreachable statement. 

Please post the full text of the error message showing Where  the unreachable statement is.  For example:


I attaching screen prints because this doesn't have a main.  I cannot run it.
JavaError1.png
[Thumbnail for JavaError1.png]
JavaError2.png
[Thumbnail for JavaError2.png]
JavaError3.png
[Thumbnail for JavaError3.png]
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any code after a return statement is not reachable.  A return statement causes the execution in a method to end.

Move the code after the return to somewhere before the return statement.

Note: Images are hard to work with.  Text can not be copied from an image to include in a response.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Any code after a return statement is not reachable.  A return statement causes the execution in a method to end.

Move the code after the return to somewhere before the return statement.

Note: Images are hard to work with.  Text can not be copied from an image to include in a response.


Do I really need to create a new set of data in order to use shoutoutrandommessage?  Isn't it a function?  So I can use the set of data I created in the canned method but re-purpose it for the random, right?
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  right?

Try it and see what happens.
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your "subjects" variable never changes so it should be made into a constant.
Change:
To:
And put it just inside your class declaration. Note that constants should be named using all uppercase characters.
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Vorpe wrote:
I'm not sure what you're trying to do here. You have no 'builder' class so you can't do 'new builder()'. You've already used Java's StringBuilder class correctly in your code so why aren't you doing the same thing here. You won't have spaces between your words here, though, so you could modify it like this.
To this:

 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This
would have been more robustly written like this
This would allow you to modify the number of Strings in the array without having to hunt down and change the magic constant '3'.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
  right?

Try it and see what happens.


It exploded, as you knew it would.  This is due at midnight.  I'm not good at this and I don't need to waste my time being hazed.  So long, everyone.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry you had problems.  It's hard to make suggestions when only bits and pieces of code are posted that are out of context.
If would be better if instead of asking "what will this do" that you actually do it and then copy the full text of any error messages and paste them here so we have something concrete to work with.

Good luck.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Sorry you had problems.  It's hard to make suggestions when only bits and pieces of code are posted that are out of context.
If would be better if instead of asking "what will this do" that you actually do it and then copy the full text of any error messages and paste them here so we have something concrete to work with.

Good luck.


This is just a class outside of a main.  I don't know how to call it in the main (another issue, I know), so I cannot give you output because the code will not run outside of the Main.
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Vorpe wrote:
Norm Radder wrote:Sorry you had problems.  It's hard to make suggestions when only bits and pieces of code are posted that are out of context.
If would be better if instead of asking "what will this do" that you actually do it and then copy the full text of any error messages and paste them here so we have something concrete to work with.

Good luck.


This is just a class outside of a main.  I don't know how to call it in the main (another issue, I know), so I cannot give you output because the code will not run outside of the Main.

Do you have a class called "Main" ? Any other classes involved? If so, could you post all of your code, including Main and whatever?
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
Do you have a class called "Main" ? Any other classes involved? If so, could you post all of your code, including Main and whatever?


Here is the shoutbox.  I've made several changes to it since last posting.



And here is the Main argument, inside my Virtual World.



Again, I call the classes and process them inside the Main.  It makes for a cleaner Main to me.
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java does not have aa "><=" operator. If you meant "not equals", then that is "!=". The exclamation point in Java means logical NOT.

Edit: Of course if you start with i=1, then the loop will never get executed.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Vorpe wrote:


The bolded and underlined code won't work.  Inside the braces, Java (NetBeans 8.1) doesn't recognize "shoutoutrandommessage".  Outside the braces, it doesn't recognize "randomSentence".  YAY!
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Java does not have aa "><=" operator. If you meant "not equals", then that is "!=". The exclamation point in Java means logical NOT.


That is weird.  The code I have is:
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  doesn't recognize "randomSentence".

randomSentence is out of scope where it is referenced.  It is defined inside of the loop's {}s and is not known outside of the {}s

What is the purpose of the loop?  I don't see anything that is changing as the loop iterates.
 
David Vorpe
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
  doesn't recognize "randomSentence".

randomSentence is out of scope where it is referenced.  It is defined inside of the loop's {}s and is not known outside of the {}s

What is the purpose of the loop?  I don't see anything that is changing as the loop iterates.


I thought it was creating a random sentence.  Obviously, I am wrong.
 
Campbell Ritchie
Marshal
Posts: 55781
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Vorpe wrote:
Carey Brown wrote:. . . Java does not have aa "><=" operator. . . .


That is weird.  The code I have is:
There is nothing weird about it at all. Just a problem in the Ranch software somewhere which occasionally adds extraneous >s.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!