当前位置:网站首页>Using enumeration to realize English to braille
Using enumeration to realize English to braille
2022-07-07 21:06:00 【No Bug】
Explain it. , Maybe you think it's funny to turn to Braille , Blind people can't see . exactly , It really doesn't make sense to simply turn to Braille , But later, a Braille Printer will be prepared for use ! Chinese to Braille will also be updated in a few days .
I know that there are still many imperfections in the procedure , It will be improved step by step .
English to braille is mainly used ASCII Code comparison table
Clear your mind first :
1. First, think about how to express Braille .
2. Because English braille is not case sensitive , All letters need to be converted to uppercase .
3. How to define the relationship between letters and Braille .
Sort out the ideas and solve them one by one .
solve the problem :
1. First, think about how to express Braille .
No matter what kind of Braille , It all consists of six points , It consists of three lines . For convenience, just use 6 Bit binary , Commas indicate line breaks .0 It means that there is no ,1 Express .
Such as :
A Braille is , Expressed as 10,00,00
H Braille is , Expressed as 10,11,00
2. Because English braille is not case sensitive , All letters need to be converted to uppercase .
java Use toUpperCase() Method can convert all letters in the string to uppercase .
And then use toCharArray() Method converts a string into an array of characters .
3. How to define the relationship between letters and Braille .
Enumeration method is used here , Easy to use , It's also pretty .
as follows :
package tobraille1.enums;
/**
* List 26 A letter of Braille
*/
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;
}
}
Just briefly introduce enumeration classes .
1. Creating enum Class time ,Java By default, this class inherits enum, therefore enum Class can no longer inherit other classes .
2. stay enum Class , The created instance must be placed on the top of the class , Multiple instances are separated by commas , If the instantiation constant is not initialized , The system will provide a parameterless Construction method
3. If the instance is initialized , You must create a constructor with corresponding parameters .
4、 If there are abstract methods in the enumeration class , Note that the abstract method should be placed after the instance . Then each instance needs to implement this abstract method in the enumeration class .
public enum Season {
SPING(" spring "){
@Override public String doPlay() {
return " spring ";
}
},SUMMMER(" summer "){
@Override public String doPlay() {
return " summer ";
}
},FALL(" autumn "){
@Override public String doPlay() {
return " autumn ";
}
}, WINTER(" winter "){
@Override public String doPlay() {
return " winter ";
}
};private final String seansonName;
Season(String seansonName) {
this.seansonName = seansonName;
}public abstract String doPlay();
}
Finally, the source code of English to braille is attached :
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 {
// English translation Braille
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);
}
// Chinese translation Braille
else {
return R.success("");
}
} catch (Exception e) {
e.printStackTrace();
return R.error(" There is an error , Translation failure ");
}
}
public static void main(String[] args) {
ToBrailleMsg toBrailleMsg = new ToBrailleMsg();
toBrailleMsg.setLanguage("en-us");
toBrailleMsg.setText("hello");
toBraille(toBrailleMsg);
}
}
Running results .
边栏推荐
- 私募基金在中国合法吗?安全吗?
- ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- Cantata9.0 | 全 新 功 能
- Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
- CodeSonar网络研讨会
- Jetty: configure connector [easy to understand]
- 死锁的产生条件和预防处理[通俗易懂]
- OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
- 201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
- 浅解ARC中的 __bridge、__bridge_retained和__bridge_transfer
猜你喜欢
Measure the height of the building
MySQL storage expression error
【OpenCV 例程200篇】223. 特征提取之多边形拟合(cv.approxPolyDP)
Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
Mysql子查询关键字的使用方式(exists)
Codesonar Webinar
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
Ubuntu安装mysql8遇到的问题以及详细安装过程
使用枚举实现英文转盲文
随机推荐
AADL Inspector 故障树安全分析模块
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
Codeforces round 275 (Div. 2) C – diverse permutation (construction) [easy to understand]
上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Codesonar Webinar
Implement secondary index with Gaussian redis
Differences and connections between MinGW, mingw-w64, tdm-gcc and other tool chains "suggestions collection"
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
现在网上开户安全么?想知道我现在在南宁,到哪里开户比较好?
CodeSonar通过创新型静态分析增强软件可靠性
How to meet the dual needs of security and confidentiality of medical devices?
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
Static analysis of software defects codesonar 5.2 release
SQL注入报错注入函数图文详解
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System
Codesonar enhances software reliability through innovative static analysis
MinGW MinGW-w64 TDM-GCC等工具链之间的差别与联系「建议收藏」
[award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
[function recursion] do you know all five classic examples of simple recursion?