मैं मोर्स कोड को टेक्स्ट में बदलने की कोशिश कर रहा हूं।जावा: मोर्सकोड कनवर्टर
मेरे पास इस समस्या के साथ उपयोग करने के लिए दो टेक्स्ट फ़ाइलें हैं। morseCode.txt: मेरे पास एक फ़ाइल है जिसे मैंने पढ़ा है जिसमें अक्षरों और संबंधित मोर्स कोड समतुल्य हैं।
morse.dat: इसका फ़ाइल कि मोर्स कोड में एन्क्रिप्टेड संदेश शामिल
मैं पहली बार फ़ाइल ठीक से पढ़ने के लिए और उसके बाद अलग विन्यास में, तो स्टोर में सक्षम था। मैंने अक्षरों और सरणी मोर्स कोड के लिए सरणी मुद्रित करके इसका परीक्षण किया और पाया कि यह इसे ठीक से और क्रम में संग्रहीत करता है।
मुझे दूसरी फ़ाइल संदेश पढ़ने में समस्याएं आ रही हैं।
- .... .. ...
.. ...
.-
- . ... -
.--. .-. --- --. .-. .- -- .-.-.-
.. ..-.
-.-- --- ..-
... . .
- .... .. ...
-- . ... ... .- --. .
- .... .- -
.. ...
--. --- --- -..
-. . .-- ...
-.-- --- ..- .-.
.--. .-. --- --. .-. .- --
.-- --- .-. -.- ... .-.-.-
इसके ouput करने वाला:
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
S ...
T -
U ..-
V ...-
W .--
X -..-
Y -.--
Z --..
0 -----
1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
. .-.-.-
, --..--
? ..--..
इस तरह क्या Message.txt फ़ाइल लग रहा है: यह morseCode.txt कुंजी है
THIS IS A TEST PROGRAM.
IF YOU SEE THIS MESSAGE THAT IS GOOD NEWS YOUR PROGRAM WORKS.
+++ यह मेरा समाधान है। +++
/*
*This is a program that translates Morse Code to English text. The key is read from a file.
*
*The file contains the equivalent letters and Morse code. The entire key is stored in an array for reference.
*
*A second file contains the encrypted message. The program reads the message file and converts individual Morse code
*
*letters into alphabet letters. The results are displayed and printed out to another file. */
import java.io.*;
import java.util.Scanner;
//file writer and print writer to save the output
public class Assignment4
{
@SuppressWarnings("null")
public static void main (String [] args) throws IOException
{
//arrays for letters and Morse Code values
String[] letter = new String[39], morseCode = new String[39];
//this is the file with the letters and morse code equivalent
File file1 = new File ("c:/morseCode.txt");
Scanner in = new Scanner(file1);
int i = 0;
while (in.hasNext())
{
//read in letter
letter[i] = in.next();
//read in Morse Code
morseCode[i] = in.next();
i++;
}
//this is the file with encrypted message
String morseLine, morseLetter, theLetter = " ";
//this file contains the encrypted message
File file2 = new File ("c:/morse.dat");
Scanner data = new Scanner(file2);
//this appends the data to the file and keeps a running input
FileWriter fWriter = new FileWriter("c:/Message.txt", true);
PrintWriter outPutFile = new PrintWriter(fWriter);
boolean found;
int number = morseCode.length;
while (data.hasNext())
{
//reads each line of mesage
morseLine = data.nextLine();
i = 0;
int j = 0, k = 0;
j = morseLine.indexOf(" ");
while (j != -1)
{
//determines the end of a letter in Morse code and stores the
morseLetter = morseLine.substring(i, j);
found = false;
k = 0;
theLetter = " ";
//this loop searches the array of morseCode for the equal Morse code letter
//then it assigns the corresponding letter that is equivalent
while (k < number && !found)
{
if (morseLetter.equals(morseCode[k]))
{
theLetter = letter[k];
found = true;
}
else
{
k++;
}
}
//this condition prints the equivalent letter of the Morse code letter
//on the message
if (!theLetter.equals(" "))
{
System.out.print(theLetter);
outPutFile.print(theLetter);
}
i = j + 1;
j = morseLine.indexOf(" ", i);
}
if(theLetter.equals("."))
{
//moves to the next line at the end of the sentence
System.out.println("");
outPutFile.println("");
}
else
{
//this separates the letters into words
System.out.print(" ");
outPutFile.print(" ");
}
}
outPutFile.close();
}
}
हाय मार्क, मैं आपके समाधान का पालन नहीं कर सका लेकिन मैं एक समाधान के साथ आया था। हम अपने पाठ्यक्रम में ऑब्जेक्ट उन्मुख प्रोग्रामिंग में शुरुआत नहीं कर रहे हैं क्योंकि यह एक स्टार्टर क्लास है। क्या आप मुझे अपने बुफर्ड रीडर का उपयोग करके समस्या का पूरा समाधान दिखा सकते हैं। मैंने अपना समाधान ऊपर ऊपर पोस्ट किया। धन्यवाद। – HelloWorld
हमें सिखाया नहीं गया है कि तरीके बीटीडब्ल्यू का उपयोग कैसे करें। कुछ लोग सोच रहे हैं कि मेरा कोड ऐसा क्यों है। – HelloWorld