当前位置: 首页 > news >正文

JAVA默写单词小程序

编写一个记单词默写单词两个功能的小程序

 

package com.lu.word;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class A {private String k;private String v;}
package com.lu.word;import java.io.FileReader;
import java.io.IOException;
import java.util.*;public class English {//单词计分private static int scoring = 0;public static void main(String[] args) {while (true) {System.out.println("1.开始背单词 2.默写单词中文意思 3.退出");Scanner scanner = new Scanner(System.in);int num = 0;while (true) {try {num = scanner.nextInt();} catch (Exception e) {System.out.println("输入错误,请重新输入");scanner.nextLine(); // 清除错误的输入continue;}break;}switch (num) {case 1:System.out.println("开始背单词");Properties properties = new Properties();try(FileReader fileReader = new FileReader("resource/work.properties");){properties.load(fileReader);properties.forEach((k,v)->{try {Thread.sleep(2000);System.out.println(k+" : "+v);} catch (InterruptedException e) {throw new RuntimeException(e);}});} catch (IOException e) {throw new RuntimeException(e);}break;case 2:Properties properties1 = new Properties();try (FileReader fileReader = new FileReader("resource/work.properties");) {properties1.load(fileReader);System.out.println("开始默写单词中文意思");HashMap<Integer, A> map = new HashMap<>();final int[] a = {1};properties1.forEach((k, v) -> map.put(a[0]++, new A((String) k, (String) v)));//判断生成的随机数是否在这个数组中int[] arr =new int[10];//随机数对象Random random = new Random();//生成一个1到map的长度之间的随机数for (int j = 0; j <10 && j< map.size() ; j++) {int i;//判断生成的随机数是否在这个数组中while (true){i = random.nextInt(1,map.size()+1);//判断生成的随机数是否在这个数组中if (!WordService.contains(arr, i)) {break;}}for (int k = 0; k < 3; k++) {System.out.println("请输入单词翻译");System.out.println(map.get(i).getK());String next = scanner.next();if (next.equals(map.get(i).getV())) {scoring += 10;System.out.println("正确");break;} else {System.out.println("错误");}}arr[j] = i;}System.out.println("你的得分是:"+scoring);} catch (IOException e) {throw new RuntimeException(e);}break;case 3:System.out.println("退出");System.exit(0);break;default:System.out.println("输入错误,请重新输入");break;}}}
}
package com.lu.word;public class WordService {/*** 判断数组中是否包含某个数字* @param arr 数组*/public static boolean contains(int[] arr, int num) {for (int j : arr) {if (j == num) {return true;}}return false;}}

http://www.lryc.cn/news/409625.html

相关文章:

  • 认知、情绪、情感、意志、人格
  • 解析capl文件生成XML Test Module对应的xml工具
  • Java中的反射是怎么回事?
  • 07 STM32寄存器开发基础-中断编程
  • 聚簇和非聚簇索引/Btree和B+tree
  • 清华学姐熬夜肝了15天的软件测试面试题出炉(附答案)建议收藏!
  • Docker 安装指南
  • 系统架构设计师 - 知识产权与标准化
  • 【Python】Facebook开源时间序列数据预测模型Prophet
  • Spring 常用的三种拦截器详解
  • 微前端概念
  • FFmpeg实战 - 解复用解码
  • Jmeter混合压测(2407)
  • Prometheus各类监控及监控指标和告警规则
  • G120 EPos配置方案及应用场景
  • 定制化爬虫管理:为企业量身打造的数据抓取方案
  • Javascript面试基础6【每日更新10】
  • CTF Web信息搜集 25000字详解
  • MSPM0G3507之电赛小车
  • linux运维一天一个shell命令之vmstat详解
  • 前端开发调试工具推荐分类整理
  • http协议与nginx
  • 一款国外开发的高质量WordPress下载站模板主题
  • Laravel为什么会成为最优雅的PHP框架
  • 孤儿进程的例子
  • CSS前端面试题——怎么用CSS实现一个宽高自适应的正方形?
  • 谷粒商城实战笔记-56~57-商品服务-API-三级分类-修改-拖拽功能完成
  • Shader入门精要总结(二)矩阵
  • 基于CentOS Stream 9平台安装MySQL Community Server 9.0.1 Innovation
  • 正则采集器之五——商品匹配规则