Question

Program Description: A Java program is to be created to produce Morse code. The Morse code...

Program Description: A Java program is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented system, a space is indicated by a short period of time during which no sound is transmitted. The international version of the Morse code is stored in the data file Morse.txt.

To process the program, the Morse code data file (Morse.txt) should be read and stored in memory for fast access to the code. Each letter of the alphabet has a Morse code equivalent. After the code table is stored, the user should be prompted for an English language phrase to be entered from the keyboard. This phrase should be encoded into Morse and displayed. One blank should be used to separate each Morse-coded letter and three blanks should be used to separate each Morse-coded word. The user should be allowed to continue with the process of entering a phrase and having it encoded until a sentinel value (0) is received.

Input: The letters and their equivalents are stored in a data file named Morse.txt. Input will consist of the Morse.txt file and well as the sentences entered from the keyboard. The data file should be read and loaded into memory at the beginning of the program before the sentences can be read and encoded. Each line of the data file contains the letter of the alphabet followed by the code equivalent. The data file should be read and stored as a collection in memory for fast and easy access during the program duration. When a sentence is read from the keyboard, it can be translated from the data stored from the Morse code file. The type of collection that can be used to store the Morse code file may be arrays.


Sample of Morse.txt:

A .-

                    B   -…

                    C   -.-.

                    D   -..

                    E   .

                    .

                   .

                   .

                    Z   --..

Output: Output will consist of the display of the original sentence and it Morse code equivalent.

Requirements:

Required name for the main program: Morse.java   

You will need to write a separate user-defined class for this program. Please name that Code.java

You must use the Java class ArrayList to create the array objects which store the codes and letters.

You must use the Java class JOptionPane to input the sentences to be translated.

Hints:

In the beginning of the program, read the Morse.txt file and store the data items in parallel ArrayList objects (String data type will be the easiest to work with; however you can use Character if you wish).

When reading the data from the line, the nextline methods can be used since the data items are String data type.

Methods from the String class can be used to separate the 2 data items in the line.

After the file is read and loaded into memory, the user can begin to enter the sentences to be coded.

Continue to process until the user has finished entering sentences.

Morse.txt

1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
0 -----
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 0
Add a comment Improve this question Transcribed image text
Answer #1


The two programs are pasted below, to keep the formatting i put them into links if you want to not worry about needing to redo it.
http://codepad.org/mxYnLEnU <== Morse.java
http://codepad.org/pWL6o0Xe <==Translate.java
http://codepad.org/CPN3lZiw <== Morse.txt

All of these are copied below, but i suggest you dont read them as it will be a jumbled mess.
MORSE.txt
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 ----.
. .-.-.- , --..-- : ---... ? ..--.. ' .----. - -....- / -..-. ( -.--.- ) -.--.- " .-..-. @ .--.-. = -...-

Morse.java
import java.util.Scanner;

public class Morse
{

public static void main(String[] args)
{
//Initialized our translate & scanner
Translate t = new Translate();
Scanner in = new Scanner(System.in);
//Asks for user input.
System.out.println("Please enter a sentence to be translated into morse code:");
String i=in.nextLine();
//Keep going until 0 is entered
while(!i.equals("0"))
{
//Translates
System.out.println(t.translate(i));
//Preps for next interation through loop
System.out.println("Please enter a sentence to be translated into morse code:");
i=in.nextLine();
}
}
/**
* Loads the morse code from file into Map
*/
}

Translate.java
import java.io.File;
import java.util.Scanner;

public class Translate
{
//Private arrays to change from languages
private String[] key;
private String[] value;

public Translate()
{
//Sets the arrays to the size of characters inside of the Morse.txt file
key= new String[55];
value = new String[55];
load();
}
//Goes through each word and changes
public String translate(String in)
{
//We need to keep it equal to the formatting we loaded everything in as.
in=in.toUpperCase();
//Create scanner from our line of text
Scanner text = new Scanner(in);
String returnThis="";
while(text.hasNext())
{
returnThis+=getMorseWord(text.next());
}
return returnThis;
}
//Gets the entire word in morse code
private String getMorseWord(String s)
{
String returnThis = "";
for(int i=0;i<s.length();i++)
{
returnThis+=getMorse(s.charAt(i))+" ";
}
return returnThis+" ";
}
//Changes the char to morse code
private String getMorse(char c)
{
for(int i=0;i<key.length;i++)
{
//If we find the characte return its value
if(key[i].equals(c+""))
return value[i];
}
//If we cannot find the character just return it.
return c+"";
}
//Loads the file Morse.txt into the arrays.
private void load()
{
try
{
Scanner fileIn = new Scanner(new File("Morse.txt"));
int i=0;
// Just set every odd value as a key and every even value as a value
while(fileIn.hasNext())
{
key[i]=fileIn.next();
//Makes it unified to our input
key[i]=key[i].toUpperCase();
value[i]=fileIn.next();
i++;
}
}
//If we cannot find the file say so.
catch(Exception e)
{
System.out.println("404 File not found");
}
}
}

answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
Program Description: A Java program is to be created to produce Morse code. The Morse code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program Description: A C# app is to be created to produce Morse code. The Morse code...

    Program Description: A C# app is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • Java Programming Part 1 File encryption is the science of writing the contents of a file...

    Java Programming Part 1 File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a...

  • Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A...

    Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...

  • msp430 launchpad 2553 C programming Write a program for the microcontroller that flashes the Morse code pattern of a string. The Morse code is a system used to transmit characters and numbers through...

    msp430 launchpad 2553 C programming Write a program for the microcontroller that flashes the Morse code pattern of a string. The Morse code is a system used to transmit characters and numbers through light or sound signals. Each character is mapped to a series of ‘dots’ and ‘dashes’ as shown below. For example, the letter A is (dot-dash), the letter B is (dash-dot-dot-dot) etc. To show a Morse letter on the microcontroller, the LED blinks for a short duration to...

  • Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program...

    Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program is required that allows a user to encode text using any of three possible ciphers. The three ciphers you are to offer are: Caesar, Playfair and Columnar Transposition. • The program needs to loop, repeating to ask the user if they wish to play with Caesar, Playfair or Columnar Transposition until the user wishes to stop the program. •For encoding, the program needs to...

  • JAVA (Student Poll) Figure 7.8 contains an array of survey responses that’s hard coded into the...

    JAVA (Student Poll) Figure 7.8 contains an array of survey responses that’s hard coded into the program. Suppose we wish to process survey results that are stored in a file. This exercise requires two separate programs. First, create an application that prompts the user for survey responses and outputs each response to a file. Use a Formatter to create a file called numbers.txt. Each integer should be written using method format. Then modify the program in Fig. 7.8 to read...

  • Please help with program this. Thank you so much in advance! Create a Java program which...

    Please help with program this. Thank you so much in advance! Create a Java program which implements a simple stack machine. The machine has 6 instructions Push operand Puts a value on the stack. The operand is either a floating point literal or one of 10 memory locations designated MO M9 Pop operand Pops the value on the top of the stack and moves it to the memory location MO-M9 Add Pops the top two values off the stack, performs...

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • Help with writing morse code

    Screen Shot 2021-03-17 at 9.57.42 AM.pngScreen Shot 2021-03-17 at 9.57.49 AM.png3 Decoding a Morse Code messageIn this exercise you will decipher a Morse code message sent to Agent 008 by Agent \(007 .\) The last words of Agent 007 were "The future of technology lies in \(\ldots\) " at which point she produced a memory stick containing a MATLAB file ctftmod.mat. The file ctftmod \(.\) mat contains the following:af, bf the denominator and numerator coefficients of a lowpass filter, whose...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT