当前位置:网站首页>使用枚举实现英文转盲文
使用枚举实现英文转盲文
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);
}
}
运行结果。

边栏推荐
- Useful win11 tips
- ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- Tensorflow2.x下如何运行1.x的代码
- Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
- Splicing and splitting of integer ints
- Mrs offline data analysis: process OBS data through Flink job
- Écrivez une liste de sauts
- Intelligent software analysis platform embold
- [award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
- Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
猜你喜欢

ISO 26262 - 基于需求测试以外的考虑因素

智能软件分析平台Embold

ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your

Cantata9.0 | new features

Implement secondary index with Gaussian redis

I Basic concepts

Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance

大厂经典指针笔试题

Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围
Klocwork 代码静态分析工具
随机推荐
Useful win11 tips
让这个CRMEB单商户微信商城系统火起来,太好用了!
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
字符串中数据排序
程序猿赚的那点钱算个P啊!
[philosophy and practice] the way of program design
【奖励公示】第22期 2022年6月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
Introduction to referer and referer policy
How to choose fund products? What fund is suitable to buy in July 2022?
深度学习模型压缩与加速技术(七):混合方式
【函数递归】简单递归的5个经典例子,你都会吗?
Apifox 接口一体化管理新神器
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System
Referrer和Referrer-Policy简介
开发一个小程序商城需要多少钱?
Jenkins 用户权限管理
如何挑选基金产品?2022年7月份适合买什么基金?
一. 基础概念
With st7008, the Bluetooth test is completely grasped
Flask1.1.4 werkzeug1.0.1 source code analysis: Routing