当前位置:网站首页>使用枚举实现英文转盲文
使用枚举实现英文转盲文
2022-07-07 18:42:00 【No Bug】
解释一下,可能大家觉得转盲文很搞笑,盲人又看不见。确实,单纯就转盲文确实没意义,但是后续会准备一台盲文打印机配合使用!过几天也会更新中文转盲文。
我深知还有程序还有许多不完善的地方,会一步步完善的。
英文转盲文主要是利用ASCII码对照表

先理清思路:
1.首先思考改如何把盲文表示出来。
2.由于英文盲文不区分大小写,需把所有字母转换为大写。
3.怎么定义字母与盲文之间的关系。
理清思路后一个个解决。
解决问题:
1.首先思考改如何把盲文表示出来。
不管哪种盲文,都是由六个点,共三行组成。方便表示就用6位二进制,逗号表示换行。0表示那个点没有,1表示有。
如:
A的盲文是
,表示为 10,00,00
H的盲文是
,表示为 10,11,00
2.由于英文盲文不区分大小写,需把所有字母转换为大写。
java使用toUpperCase()方法可以把字符串中的所有字母转为大写。
然后使用 toCharArray() 方法把字符串转化为一个字符数组。
3.怎么定义字母与盲文之间的关系。
这里使用了枚举法,使用比较方便,也比较好看。
如下:
package tobraille1.enums;
/**
* 枚举出26个字母的盲文
*/
public enum BrailleEnum {
A("10,00,00"),
B("10,10,00"),
C("11,00,00"),
D("11,01,00"),
E("10,01,00"),
F("11,10,00"),
G("11,11,00"),
H("10,11,00"),
I("00,11,00"),
J("01,11,00"),
K("10,00,10"),
L("10,10,10"),
M("11,00,10"),
N("11,01,10"),
O("10,01,10"),
P("11,10,10"),
Q("11,11,10"),
R("10,11,10"),
S("01,10,10"),
T("01,11,10"),
U("10,00,11"),
V("10,10,11"),
W("01,11,01"),
X("11,00,11"),
Y("11,01,11"),
Z("10,01,11");
private String braille;
BrailleEnum(String braille) {
this.braille = braille;
}
public String getBraille() {
return braille;
}
public void setBraille(String ASCII) {
this.braille = ASCII;
}
}
随便简单介绍一下枚举类。
1.在创建enum类的时候,Java就默认这个类继承了enum,所以enum类是无法再继承其他类。
2.在enum类中,创建的实例必须放在类的最上面,多个实例用逗号隔开,如果实例化常量没有初始化,系统会默认提供一个无参的构造方法
3.如果实例初始化了,就必须创建带有对应参数的构造函数。
4、如果枚举类中有抽象方法,注意抽象方法要放在实例的后面。则每个实例都需要实现枚举类中的这个抽象方法。
public enum Season {
SPING("春天"){
@Override public String doPlay() {
return "春天";
}
},SUMMMER("夏天"){
@Override public String doPlay() {
return "夏天";
}
},FALL("秋天"){
@Override public String doPlay() {
return "秋天";
}
}, WINTER("冬天"){
@Override public String doPlay() {
return "冬天";
}
};private final String seansonName;
Season(String seansonName) {
this.seansonName = seansonName;
}public abstract String doPlay();
}
最后附上英文转盲文的源码:
package tobraille1.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import tobraille1.POJO.EnASCIIToBraille;
import tobraille1.POJO.ToBrailleMsg;
import tobraille1.common.R;
import tobraille1.dao.ToBrailleMsgDao;
import tobraille1.enums.BrailleEnum;
import java.util.Map;
@Service
public class ToBrailleImpl extends ServiceImpl<ToBrailleMsgDao, ToBrailleMsg> {
public static R<String> toBraille(ToBrailleMsg brailleMessage) {
try {
//英文翻译盲文
if ("en-us".equals(brailleMessage.getLanguage())) {
String upperCase = brailleMessage.getText().toUpperCase();
char[] chars = upperCase.toCharArray();
String[] s = new String[chars.length];
int i = 0;
for (char c : chars) {
s[i] = BrailleEnum.valueOf(String.valueOf(c)).getBraille();
System.out.println(s[i]);
i++;
}
return R.success(s);
}
//中文翻译盲文
else {
return R.success("");
}
} catch (Exception e) {
e.printStackTrace();
return R.error("出现错误,翻译失败");
}
}
public static void main(String[] args) {
ToBrailleMsg toBrailleMsg = new ToBrailleMsg();
toBrailleMsg.setLanguage("en-us");
toBrailleMsg.setText("hello");
toBraille(toBrailleMsg);
}
}
运行结果。

边栏推荐
- C语言多角度帮助你深入理解指针(1. 字符指针2. 数组指针和 指针数组 、数组传参和指针传参3. 函数指针4. 函数指针数组5. 指向函数指针数组的指针6. 回调函数)
- H3C s7000/s7500e/10500 series post stack BFD detection configuration method
- [résolution] le paquet « xxxx» n'est pas dans goroot
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
- ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- Mongodb由浅入深学习
- Apifox interface integrated management new artifact
- 使用camunda做工作流设计,驳回操作
- Codesonar enhances software reliability through innovative static analysis
- How C language determines whether it is a 32-bit system or a 64 bit system
猜你喜欢

使用高斯Redis实现二级索引

Nebula Importer 数据导入实践

OneSpin | 解决IC设计中的硬件木马和安全信任问题

Splicing and splitting of integer ints
![Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]](/img/af/61b384b1b6ba46aa1a6011f8a30085.png)
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]

Jenkins 用户权限管理

VMWare中虚拟机网络配置

H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法

Dachang classic pointer written test questions

With st7008, the Bluetooth test is completely grasped
随机推荐
Network principle (1) - overview of basic principles
POJ 1742 Coins ( 单调队列解法 )「建议收藏」
How does codesonar help UAVs find software defects?
Cantata9.0 | 全 新 功 能
测量楼的高度
Numerical method for solving optimal control problem (0) -- Definition
Micro service remote debug, nocalhost + rainbow micro service development second bullet
【函数递归】简单递归的5个经典例子,你都会吗?
机械臂速成小指南(十一):坐标系的标准命名
Implement secondary index with Gaussian redis
神兵利器——敏感文件发现工具
Apifox interface integrated management new artifact
Cantata9.0 | new features
C语言多角度帮助你深入理解指针(1. 字符指针2. 数组指针和 指针数组 、数组传参和指针传参3. 函数指针4. 函数指针数组5. 指向函数指针数组的指针6. 回调函数)
Data sorting in string
使用 BR 恢复 Azure Blob Storage 上的备份数据
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
Introduction to referer and referer policy
One click deployment of any version of redis
How to choose financial products? Novice doesn't know anything