• Post Reply Bookmark Topic Watch Topic
  • New Topic

Morse code program. No output?  RSS feed

 
Matt Beckner
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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:




 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • 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 ?
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Brian Schuetz
Greenhorn
Posts: 25
Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thats my problem. How can I make them load the right way? I can't figure that out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!