• 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

Morse code program. No output?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The purpose of this program is to translate a user inputed sentence into morseCode. It seems like everything is right to me, but I'm simply not getting output! What am I doing wrong, or what should I add/change? Any help is greatly appreciated.

Here is the main class:



TESTER CLASS:




 
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ! Could you put your code in [c ode ] tags ? It makes it much easier to read.

As for your code problem, its not clear to me what the return of morse is ? When you use the debugger, are you getting valid return values ?
 
Marshal
Posts: 4489
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Since you are comparing the ith character in the input string to the ith character in the alphabet array, it seems like you would only get matches (and output) when the input string resembles the alphabet string. What do you get with an input of ABCXXFG?

.... . .-.. .-.. --- .-- --- .-. .-.. -..
 
Matt Beckner
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Morse contains the morse code read in from the text file. I understand what your saying with that particular line of code, how do you suppose I go about changing it? Thanks for replying.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest using a data structure like Map<Character, String> morse where the key is a letter, and the value is the morse code for that letter.
 
Ron McLeod
Marshal
Posts: 4489
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You code use another loop to scan through the alphabet array looking for a match. If a match is found, you would know the offset where it was found in the alphabet array, and could use that to look-up the corresponding value in the code array.

Update: As Ulf suggested, a Map would be even better if that is an option for you.
 
Matt Beckner
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't gotten to maps yet, but could you give an example of the loop you are referring to? It would be a great help.
 
Greenhorn
Posts: 25
Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a suggestion, add a nested for loop with a different loop counter (for example use j)

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



I had the same idea earlier and did this. Still no output!

Also my morse code does read in properly from the txt file.
 
Ron McLeod
Marshal
Posts: 4489
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your updated translation method looks like it should work, but obviously you will need to be able to get the array of codes loaded-up properly to have your application to perform as expected.
 
Matt Beckner
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats my problem. How can I make them load the right way? I can't figure that out.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic