/*
*
* The Code below converts Alphanumeric text or words to Morse code
*
*
* */
import javax.swing.JOptionPane;
public class TextorNumbersToMorseCode {
protected char[] alphabetandNum = { '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', '1', '2', '3', '4', '5', '6', '7','8',
'9', '0'};
private String[] morse = { /*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*/"--..", /*1*/".----", /*2*/"..---", /*3*/"...--", /*4*/"....-", /*5*/".....",
/*6*/"-....", /*7*/"--...", /*8*/"---..", /*9*/"----.", /*0*/"-----"}; //morse code array
protected String input;
protected String output;
/*-- Class Constructor --*/
public TextorNumbersToMorseCode()
{
this.input = null;
this.output = "";
}
/*-- End Class Constructor --*/
/* Getter and Setter methods */
public String getInput()
{
return this.input;
}
public void setInput(String input)
{
this.input = input;
}
/* End Getter and Setter methods */
/* Morse Code Method */
public void morseCode(String input)
{
try
{
this.input = input;
for(int i = 0; i <= input.length() - 1; i++)
{
for(int y = 0; y <= alphabetandNum.length - 1; y++)
{
if(input.charAt(i) == alphabetandNum[y])
{
output += morse[y] +" ";
}
}
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Please enter a word or whole number only. \n Try again ");
}
}
public String toString()
{
return "Morse Code of "+input.toUpperCase()+" is "+this.output;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java Text to Morse Code and Binary.zip
共11个文件
class:3个
java:3个
py:1个
需积分: 5 0 下载量 107 浏览量
2024-01-08
10:49:18
上传
评论
收藏 10KB ZIP 举报
温馨提示
Java Text to Morse Code and Binary.zip
资源推荐
资源详情
资源评论
收起资源包目录
Text to Morse Code and Binary.zip (11个子文件)
TextToBinaryAndMorseCode
.classpath 301B
.settings
org.eclipse.jdt.core.prefs 8KB
src
TextorNumbersToBinary.java 2KB
TestMorses.java 961B
TextorNumbersToMorseCode.java 2KB
bin
TextorNumbersToBinary.class 2KB
TextorNumbersToMorseCode.class 2KB
TestMorses.class 2KB
.project 400B
.gitignore 6B
sourcecodester_java.py 2KB
共 11 条
- 1
资源评论
xiaoshun007~
- 粉丝: 3817
- 资源: 3145
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功