This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

help with Switch Statement

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
lowercase baba
Posts: 13003
66
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 74085
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13003
66
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic