• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with Switch Statement  RSS feed

 
John Marko
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can someone help me on converting the following Ruby switch Statement into a Java switch statement?




Thank you in advance for your help!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried? Do you know what a basic Java switch statement looks like?
 
John Marko
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:What have you tried? Do you know what a basic Java switch statement looks like?



Thank Fred for your swift reply!

I have tried the following but its totally wrong


 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with it?
Are you getting compilation errors?  If so, then what are they and what line(s) do they occur on?

If not, then what is the issue?
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I added code tags to your posts: they even have an option for Ruby highlighting. Always use the tags: doesn't it look better
I would suggest you shou‍ld not try to translate the switch statement from one language to another. For one thing, you get variable names with _ in which is not the normal Java® style. For another, there seems to be confusion about types; in the Ruby you appear to be passing what looks like arrays, which in the Java® you have turned into Strings. I suggest you write down on paper what the switch statement is supposed to do, then create a new switch (or other statement) in Java® without looking at the Ruby code.

I am moving this discussion as too difficult for this forum.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell makes a good point. Before you can convert your Ruby into Java, you have to understand what your Ruby code is doing.

this is not valid. I'm not sure what you are trying to do here:


So stop. write out in English (or your natural lagunage of choice) what you are trying to accomplish. THEN start trying to code it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!