1.题型参考
2.应用题题库参考
3.代码
计算方式枚举
public enum NormalSumType {
//加法
Addition,
//减法
Subtraction
}
工具类
import cn.hutool.core.util.RandomUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class TopicUtil {
public static final List<String> Photos = Arrays.asList("◯", "♡", "♥", "♢", "♦", "♠", "♣", "★", "❉", "☂", "☁", "☃", "☽", "♚");
public static final List<String> ApplicationTopicList = Arrays.asList(
"同学们要做28个灯笼,已做好18个,还要做多少个?",
"从花上飞走了36只蝴蝶,又飞走了25只,两次飞走了多少只?",
"飞机场上有75架飞机,飞走了63架,现在机场上有飞机多少架?",
"小苹种7盆红花,又种了同样多的黄花,两种花共多少盆?",
"学校原有25瓶胶水,又买回19瓶,现在有多少瓶?",
"小强家有36个苹果,吃了7个,还有多少个?",
"汽车总站有33辆汽车,开走了13辆,还有几辆?",
"小朋友做剪纸 ,用了8张红纸,又用了同样多的黄纸,他们用了多少张纸?",
"马场上有39匹马,又来了52匹,现在马场上有多少匹?",
"商店有25把扇,卖去16把,现在有多少把?",
"学校有兰花和菊花共65盆,兰花有26盆,菊花有几盆?",
"小青两次画了17个 ,第一次画了9个,第二次画了多少个?",
"小红家有苹果和梨子共33个,苹果有14个,梨子有多少个?",
"学校要把42箱文具送给山区小学,已送去27箱,还要送几箱?",
"家有11棵白菜,吃了5棵,还有几棵?",
"一条马路两旁各种上48棵树,一共种树多少棵?",
"从车场开走8辆汽车,还剩24辆,车场原来有多少汽车?",
"从车场开走8辆大汽车,又开走同样多的小汽车,两次开走多少辆汽车?",
"学校体育室有6个足球 ,又买来26个,现在有多少个?",
"学雷锋小组上午修了8张椅,下午修了9张,一天修了多少张椅?",
"原来有22人看戏,来了13人,又走了6人,现在看戏的有多少人?",
"面包房做了54个面包,第一组买了22个,第二组买了8个,还剩多少个?",
"男生有22人,女生有21人,其中有16人参加比赛,还有多少人没参加?",
"三个小组一共收集了94个矿泉水瓶,第一组收集了34个,第二组收集了29个,第三组收集了多少个?",
"汽车里有41人,中途有13人上车,9人下车,车上现在还有多少人?",
"小红有28个气球,送给幼儿园小朋友15个,还剩多少个?",
"小军和小丽做灯笼,小军做了21个,小丽做了18个,送给老师50个,他们还要做多少个?",
"故事书有74页,小丽第一天看了20页,第二天看了23页,还剩多少页没有看?",
"羊圈里原来有58只羊,先走了6只,又走了7只,现在还有多少只?",
"小东上午做了10道数学题,下午做的比上午多3道,小东下午做了多少道?",
"小红看故事书,第一天看了15页,第二天看的比第一天少6页,第二天看了多少页?",
"爸爸、妈妈和哥哥都掰了9个玉米,我掰了6个,我们家一共掰了多少个玉米?",
"小明种了5行萝卜,每行9个,共种了多少个?",
"食堂运来3车大米,每车8袋,3车共多少袋?",
"我有50元,要买一件20元的衣服和一副10元的眼镜,还剩多少元?",
"学校有50个面包,每个学生分9个,可以分给多少个学生?",
"爸爸买了4捆木头,每捆12根,全部共多少根?",
"妈妈给了小明50元钱,小明要买一本数学书20元,还要买一个文具盒21元,妈妈给的钱够吗?",
"一艘船可以载60人,一年级有21人,二年级有22人,三年级有15人,三个班的人够坐吗?",
"小明家有5张桌子,每张桌子够坐8人,他们家可以请多少人来做客?",
"小红家有4块地,每块地里可以种20课菜,小红家共种了多少棵白菜?",
"学校共有38个篮球,每班分7个,可以分给多少个班?",
"我家买了38个苹果,我吃了8个,哥哥吃了10个,还剩多少个?",
"商店共有西瓜56个,上午买了15个,下午买了21个,还有多少个没买?",
"妈妈给小丽48元钱,买了一个书包还剩15元,这个书包多少钱?",
"小军拿了50元买了一个9元钱的文具盒,小军应找回多少元钱?",
"妈妈给我买了一件48元的衣服,售货员找了妈妈10元钱,妈妈给了售货员多少元钱?",
"我家养了38只鸡,过年吃了5只,过元宵节吃了3只,还剩多少只?",
"公共汽车上有35个人,到站时下了20个,又上来了9个,现在车上有多少个人?",
"田里种着56棵白菜,种的莲花白比白菜多13棵,莲花白种了多少棵?",
"水果店上午卖出桔子36箱,下午卖出27,一天共卖出多少箱?",
"蓝蓝、玲玲、小胖每人做了15朵红花,他们一共做了几朵红花?",
" 小亚带30去玩,大风车10元,小火车8元,他还剩多少钱?",
"学校送给一(1)班48只气球,还剩52只,原来学校有几只气球?",
" 苹果26个,梨18个,桔子50个,苹果、梨和桔子一共有几个?",
"小亚要做60道口算题,还剩18题没有完成,小亚已经做完几题?",
"爸爸买了2根和路雪8元,买了3根伊利雪糕6元,他付给营业员20元,找回多少元?",
"图书室有漫画60本,借出25本,还剩多少本?",
" 小巧做了27道口算,还剩18道没有做。小巧一共要做多少道口算?",
" 停车场上有35辆车,开走8辆,又开走7辆,一共开走几辆?",
"小丁丁有100元,他买了一个32元的篮球和一双40元的溜冰鞋,他还剩多少钱?",
" 书店有100本书,上午卖出45本书,下午卖出27本,一天共卖出多少本?",
" 车上有乘客56人,到站后有18人上车。现在有乘客多少人?",
"车上原有64人,有25人下车。 车上还有乘客多少人?",
"红铅笔有50支,蓝铅笔比红铅笔少8支,蓝铅笔有多少支?",
"轿车有23辆,卡车有37辆,大客车有18辆,一共有多少辆车?",
"水果店上午卖出75箱苹果,下午卖出57箱,一天一共卖出多少箱苹果?",
" 树上原来有39只鸟,又飞来8只,现在有几只?",
"停车场开走58辆汽车,还剩16辆,原来有多少辆?",
" 一共有100只气球,其中红气球有15只,蓝气球有51只,黄气球有多少只?",
"停车场上有35辆车,开走8辆,又开走7辆,一共开走几辆?",
"红黄白100只气球,其中红气球20只,黄气球50只,白气球有几只?",
"小朋友做纸花,小亚和小巧各做了20朵,小丁丁做了15朵,他们一共做了几朵纸花?",
"河里有8只鸭子,游来了14只,河里现在有多少只鸭子?",
" 商店里有65台电视机,卖掉一些后,还剩35台电视机。卖掉多少台?",
"小朋友跳绳,小亚与小巧各跳了20个,小丁丁跳了25个,他们三人共跳多少个?",
"一本书 18元,一支笔3元,一个书包68元,小胖买一本书和两支笔用去多少元?",
"星期天小胖和妈妈去超市买了一个30元的小足球和一副28元的羽毛球拍,妈妈带了3张20元,够不够?",
"小巧想把草莓分给三个好朋友,小丁丁和小胖各分到6个,小亚得到4个,正好分完。小巧原来有几个草莓?",
"小丁丁有42本课外书,先借给小亚6本,又向小胖借了9本,小丁丁现在有几本书?",
" 汽车上原有35人,到站后先下车12人,又上车8人,现在车上有几人?",
"学校交书报费,《少年时报》22元,《卡通王》38元,小丁丁带50元够吗?",
"小丁丁帮妈妈做家务,洗碗5分钟,烧水10分钟,擦桌椅5分钟,小丁丁做这些事最少用几分钟?",
"语文书12本,借走3本就与数学书一样多,数学书几本?",
"停车场有汽车60辆,第一次开走15辆,第二次开来14辆,停车场现在有几辆车?",
"小明有45本故事书,借给小丁丁17本.借给小亚14本,还剩几本?",
"小明付了50元买了一本书,营业员阿姨找回他35元,这本书要几元?",
"苗苗第一个月的零花钱是35元,第2个月是20元,第3个月是43元,苗苗三个月的零花钱一共是多少元?",
"原有29个球,借出8个,还剩多少个?",
"借出8个球,还剩21个,原有多少个?",
"买来12个苹果,吃了4个,还剩多少个?",
"吃了4个苹果,还剩8个,原来有多少个?",
"车场里开走了4辆车,还剩15辆。车场里原有多少辆车?",
"草地上的兔子跑了8只后,还剩下40只,原来有兔子多少只?",
"商店卖出汽水32箱,还剩20箱,原有汽水多少箱?",
"水果店卖出苹果76筐,还剩3筐,原有苹果多少筐?",
"小山剪了一些★,贴了31个,还剩下7个。小山剪了几个★?",
"小华看书看了92页,还剩下4页没有看。这本书有多少页?",
"英语小组原来有12个人,今天上课缺席的有2个人,今天上课的有多少人?",
"学校里有8个足球,49个小皮球,小皮球比足球多多少个?",
"商店里有26个小汽球,5个大汽球,大汽球比小汽球少多少个?",
"合唱队有38个女同学,6个男同学,男同学比女同学少多少个?",
"小明养了36只兔,小红养了24只兔,小明比小红多养了多少只?",
"商店里有35盒红汽球,20盒黄汽球,黄汽球比红汽球少多少盒?",
"梨子有5个,苹果有7个,苹果比梨子多多少个?",
"草地上有白兔7只,黑兔4只,白兔比黑兔多多少只?",
"小花8岁,爸爸38岁,爸爸比小花大几岁?",
"美术组有13人,数学组有9人,美术组比数学组多多少人?",
"草地有公鸡7只,母鸡39只,母鸡比公鸡多多少只?公鸡比母鸡少多少只?",
"食堂运回大米28袋,面粉7袋,面粉比大米少多少袋?",
"体操队有18人,游泳队比体操队多11人,游泳队有多少人?",
"水果店卖出26筐苹果后,剩下的比卖出的多9筐。剩下多少筐苹果?",
"小华有25本故事书,小方比他多11本。小方有多少本?",
"六月卖出冰箱58台,七月比六月多卖出22台。七月卖出多少台?",
"小花今年8岁,爸爸比她大29岁。爸爸今年多少岁?",
"有5个草莓,樱桃比草莓多3个,樱桃有几个?",
"小花捡了25个贝壳,小明比小花多捡了4个,小明捡了多少个贝壳?",
"数学组有9人,美术组比数学组多8人,美术组有多少人?",
"食堂运回大米28袋,面粉比大米多7袋,面粉有多少袋?",
"小明养了36只兔,小红比小明多养了3只,小红养了多少只兔?",
"商店里有35盒红汽球,黄汽球比红汽球多10盒,黄汽球有多少盒?",
"25比12多多少?",
"比32多20的数是多少?",
"一个加数是28,另一个加数比它大10,另一个加数是多少?",
"一个数比60多30,这个数是多少?",
"38比8多多少?",
"一个数是26,另一个数是58,和是多少?",
"29比7多多少?",
"比49多20的数是多少?",
"一个数比26多8,这个数是多少?",
"第一个加数是58,第二个加数是89,第一个加数比第二个加数少多少?",
"被减数是69,减数是39,被减数比减数多多少?",
"比29多29的数是多少?",
"54与67的差是多少?",
"5与38的和是多少?",
"比最大的两位数多1的数是多少?",
"一个加数是35,另一个加数比它多7,另一个加数是多少?",
"明明写毛笔字,写了13个以后,还有9个要写,明明一共要写多少个毛笔字?",
"从花上飞走了26只蝴蝶,又飞走了5只,两次飞走了多少只?",
"飞机场上有16架飞机,飞走了8架,现在飞机场上还有多少架飞机?",
"小平种7盆红花,又种了同样多的黄花,两种花共多少盆?",
"学校原有15瓶胶水,又买回9瓶,现在有多少瓶?",
"小强吃了7个苹果,剩下15个苹果,原来有多少个苹果?",
"学校有兰花和菊花共15盆,兰花有6盆,菊花几盆?",
"小丽买衣服用了30元,售货员找给她21元,小丽原来有多少钱?",
"妈妈上衣和裤子共用去79元,买上衣用去50元,买裤子用去多少元?",
"商店两次卖出洋娃娃50个,第一次卖出30个,第二次卖出几个?",
"商店两次卖出洋娃娃50个,第一次卖出30个,两次卖出多少个?",
"有60只小鸡,28只母鸡。还剩多少只?",
"有60只小鸡,28只母鸡。母鸡比小鸡少多少只?",
"有60只小鸡,28只母鸡。一共有多少只?",
"学校有兰花和菊花共16盆,兰花有6盆,菊花有几盆?",
"小青两次画了9个 ,第一次画了5个,第二次画了多少个?",
"小红家有苹果和梨子共18个,苹果有9个,梨子有多少个?",
"学校要把20箱文具送给山区小学,已送去10箱,还要送几箱?",
"家有15棵白菜,吃了5棵,还有几棵?",
"一条马路两旁各种上9棵树,一共种树多少棵?",
"从车场开走9辆汽车,还剩5辆,车场原来有多少汽车?",
"从车场开走8辆大汽车,又开走同样多的小汽车,两次开走多少辆汽车?",
"学校体育室有8个足球 ,又买来7个,现在有多少个?",
"学雷锋小组上午修了8张椅,下午修了12张,一天修了多少张椅?",
"小明和小丽一共拍了35下,小丽拍了20下,小明拍了多少下?",
"树上有20只小鸟,先飞走了7只,又飞走了6只,一共飞走了多少只?",
"校园里有18盆菊花,运走了16盆;兰花比菊花少多少盆?",
"校园里有18盆菊花,还剩下5盆,兰花比菊花少多少盆?",
"校园里有18盆菊花,兰花16盆,兰花比菊花少多少盆?",
"幼儿园买苹果50个,分给小朋友12个,还剩多少个?",
"幼儿园买苹果50个,梨比苹果少12个,还剩多少个?",
"幼儿园买苹果50个,梨比苹果多12个,还剩多少个?",
"有白兔和灰兔共30只,有白兔24只。原来有多少只?",
"有白兔和灰兔共30只,有白兔25只。有灰兔多少只?",
"有一些兔,跑了4只,还有18只。原来有多少只?",
"小猴拿了21个红果,小狗拿了18个红果,小猴和小狗谁拿得多?",
"三种邮票一共有92张,熊猫邮票23张,龙邮票38张。熊猫邮票和龙邮票共有多少张?",
"一共有96个苹果,上午卖了26个,下午卖了39个,还剩几个?",
"从前面数,小明排18,从后面他排15,这一排共有几人?",
"一个贝壳25元,一个海螺13元,用50元去买还剩 多少元?",
"小红跳了25个绳,小刚跳了36个,一共跳了几个?",
"两只青蛙一共吃了40只害虫,一只吃了15只,另一只吃了多少只?",
"男生有32瓶果汁,女生有19瓶果汁,男生比女生多几瓶?",
"小明拔萝卜,已经拔了16个,地里还剩48个,地里原有几个?",
"米奇摘了48个桃,小猴比米奇多12个,小猴摘了几个?",
"小明有37个糖果,小红比小明少19个,小红有几个?",
"一共要折43只纸鹤,已经好了19只,还要折几只?",
"小明跳了25下绳,小刚跳了17下,小刚再跳几下就和小明同样多?",
"小明跳了47个绳,小红再跳18个就和小明一样多,小红跳了几个?",
"车上原有45人,下来19人,又上来23人,现在有多少人?",
"一共有96筐苹果,上午卖了26筐,下午卖了39筐,还剩几筐?",
"一班有38人,二班有36 人,现有60顶帽子每人分一个够吗?",
"打排球的有48人,比划船的少19人,划船的有几人?",
"小兔拔了26个萝卜,比小猪多7个,小猪拔了几个?",
"从前面数,小明排18,从后面他排15,这一排共有几人?",
"一个贝壳25元,一个海螺13元,用50元去买还剩 多少元?",
"参加演出的合唱队有28人,舞蹈队的有24人,参加演出的一共有多少人?",
"爸爸今年36岁,我比爸爸小28岁,今年我几岁?",
"同学们去拍照,已经照了17张,还有19张没照,胶卷一共有多少张?",
"汽车从起始站出发,到第一站有16人下车,24人上车,现在车上有44人,有多少人在起始站上车?",
"有一些小松鼠在树上,后来跑了6只,还剩下5只,原来有几只小松鼠?",
"黄花比红花少5朵,红花有12朵,黄花有几朵?",
"两个班共种树20棵,其中一班种1棵,那么二班种了几棵树?",
"小张书包有18本书,我有3本,我比小张少几本?",
"今天,小张书包有10本书,我有11本,我比小张多几本?",
"公共汽车上下来4人,车上还坐着7人,原来车上有多少人?",
"今天,小张书包有1本书,我有19本,我比小张多几本?",
"停车场上原来有19辆汽车,第一次开走3辆,第二次开走7辆。还剩多少辆?",
"飞机场原有18架飞机,飞走13架,还剩几架?",
"公共汽车上下来1人,车上还坐着17人,原来车上有多少人?",
"鱼缸里有11条红金鱼和花金鱼,其中红金鱼有5条,花金鱼有多少条?",
"公共汽车上下来8人,车上还坐着7人,原来车上有多少人?",
"停车场上第一次开走7辆,第二次开走8辆。一共开走多少辆?",
"学校舞蹈小组有女生9人,男生10人,舞蹈小组一共有学生多少人?",
"篮里有苹果和梨一共15只,其中苹果有13只,梨有几只?",
"白兔和黑兔一共有9只,其中白兔有3只,黑兔有几只?",
"8个同学回家了,班里还剩12个同学,请问原来有几个同学?",
"妈妈买了一篮梨,小明吃了10个,还剩余3个,妈妈买了多少个梨?",
"小张书包有5本书,我有12本,小张比我少几本?",
"鱼缸里有19条红金鱼和花金鱼,其中红金鱼有9条,花金鱼有多少条?",
"借了4本书,今天还了2本,还剩几本书?",
"小飞有12张画片,送给小明一些,还剩下9张。送给小明多少张?",
"两个班共种树13棵,其中一班种12棵,那么二班种了几棵树?",
"生产队有小牛7头,大牛比小牛多8头,大牛有多少头?",
"黄花比红花多7朵,红花有11朵,黄花有几朵?",
"学校舞蹈小组有女生9人,男生2人,女生比男生多几人?",
"鱼缸里有17条红金鱼和花金鱼,其中红金鱼有15条,花金鱼有多少条?",
"篮里有苹果和梨一共18只,其中苹果有5只,梨有几只?",
"6个同学回家了,班里还剩11个同学,请问原来有几个同学?",
"黄花比红花少5朵,红花有12朵,黄花有几朵?");
/**
* 随机生成10以内的加减法
*
* @param normalSumType 算术题类型
* @return
*/
public static String randomNormalSumTopic(NormalSumType normalSumType) {
if (normalSumType == NormalSumType.Addition) {
//加法
int firstNum = RandomUtil.randomInt(1, 10);
int secondNum = RandomUtil.randomInt(1, 11 - firstNum);
return firstNum + "+" + secondNum + "=";
} else {
//减法
int firstNum = RandomUtil.randomInt(1, 10);
int secondNum = RandomUtil.randomInt(1, firstNum + 1);
return firstNum + "-" + secondNum + "=";
}
}
/**
* 随机20条10以内的加减算术题
*
* @return
*/
public static List<String> randomNormalSumTopicList() {
List<String> result = new ArrayList<>();
//随机10条加法
while (result.size() < 10) {
String item = randomNormalSumTopic(NormalSumType.Addition);
if (!result.contains(item)) {
result.add(item);
}
}
//随机10条减法
while (result.size() < 20) {
String item = randomNormalSumTopic(NormalSumType.Subtraction);
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成100以内的相邻数
*
* @return
*/
public static String randomNearNumTopic() {
int num = RandomUtil.randomInt(2, 100);
return "( )" + num + "( )";
}
/**
* 随机6条100以内的相邻数题
*
* @return
*/
public static List<String> randomNearNumTopicList() {
List<String> result = new ArrayList<>();
//随机6条相邻数
while (result.size() < 6) {
String item = randomNearNumTopic();
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成100以内的比较
*
* @return
*/
public static String randomCompareTopic() {
int firstNum = RandomUtil.randomInt(1, 100);
int secondNum = RandomUtil.randomInt(1, 100);
return firstNum + " ◯ " + secondNum;
}
/**
* 随机8条100以内的比大小题
*
* @return
*/
public static List<String> randomCompareTopicList() {
List<String> result = new ArrayList<>();
//随机8条比较大小题
while (result.size() < 8) {
String item = randomCompareTopic();
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成10以内的分解题
*
* @return
*/
public static String randomDivideTopic() {
int sum = RandomUtil.randomInt(2, 11);
int firstNum = RandomUtil.randomInt(1, sum);
if (RandomUtil.randomBoolean()) {
return sum + "_" + firstNum + " ( )";
} else {
return sum + "_" + "( ) " + firstNum;
}
}
/**
* 随机生成10以内的组合题
*
* @return
*/
public static String randomCombinationTopic() {
int firstNum = RandomUtil.randomInt(1, 10);
int secondNum = RandomUtil.randomInt(1, 11 - firstNum);
return firstNum + " " + secondNum + "_" + "( )";
}
/**
* 随机8条100以内的分解组合题
*
* @return
*/
public static List<String> randomDivideCombinationTopicList() {
List<String> result = new ArrayList<>();
//随机4条分解题
while (result.size() < 4) {
String item = randomDivideTopic();
if (!result.contains(item)) {
result.add(item);
}
}
//随机4条组合题
while (result.size() < 8) {
String item = randomCombinationTopic();
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成10以内的看图计算题
*
* @return
*/
public static String randomPhotoComputeTopic(NormalSumType normalSumType) {
String photo = Photos.get(RandomUtil.randomInt(0, Photos.size()));
if (normalSumType == NormalSumType.Addition) {
//加法
int firstNum = RandomUtil.randomInt(1, 10);
int secondNum = RandomUtil.randomInt(1, 11 - firstNum);
return getPhotoStr(photo, firstNum) + " + " + getPhotoStr(photo, secondNum);
} else {
//减法
int firstNum = RandomUtil.randomInt(1, 10);
int secondNum = RandomUtil.randomInt(1, firstNum + 1);
return getPhotoStr(photo, firstNum) + " - " + getPhotoStr(photo, secondNum);
}
}
/**
* 随机4条100以内的看图计算题
*
* @return
*/
public static List<String> randomPhotoComputeTopicList() {
List<String> result = new ArrayList<>();
//随机2条加法题
while (result.size() < 2) {
String item = randomPhotoComputeTopic(NormalSumType.Addition);
if (!result.contains(item)) {
result.add(item);
}
}
//随机2条减法题
while (result.size() < 4) {
String item = randomPhotoComputeTopic(NormalSumType.Subtraction);
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成10以内数相加(凑10法)
*
* @return
*/
public static String randomSecondSumTopic() {
int firstNum = RandomUtil.randomInt(2, 10);
int secondNum = RandomUtil.randomInt(11 - firstNum, 10);
return firstNum + "+" + secondNum + "=";
}
/**
* 随机3条10以内数相加
*
* @return
*/
public static List<String> randomSecondSumTopicList() {
List<String> result = new ArrayList<>();
while (result.size() < 3) {
String item = randomSecondSumTopic();
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成10以内的加减法连线
*
* @param normalSumType 算术题类型
* @return
*/
public static String randomLinkTopic(NormalSumType normalSumType) {
if (normalSumType == NormalSumType.Addition) {
//加法
int firstNum = RandomUtil.randomInt(1, 10);
int secondNum = RandomUtil.randomInt(1, 11 - firstNum);
return firstNum + "+" + secondNum + "=" + (firstNum + secondNum);
} else {
//减法
int firstNum = RandomUtil.randomInt(1, 10);
int secondNum = RandomUtil.randomInt(1, firstNum + 1);
return firstNum + "-" + secondNum + "=" + (firstNum - secondNum);
}
}
/**
* 随机5条10以内的加减算术题
*
* @return
*/
public static List<String> randomLinkTopicList() {
List<String> result = new ArrayList<>();
while (result.size() < 5) {
String item;
if (RandomUtil.randomBoolean()) {
item = randomLinkTopic(NormalSumType.Addition);
} else {
item = randomLinkTopic(NormalSumType.Subtraction);
}
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成1x以内数相减(借十法)
*
* @return
*/
public static String randomThirdSubTopic() {
int firstNum = RandomUtil.randomInt(11, 20);
int secondNum = RandomUtil.randomInt(firstNum - 10, 10);
return firstNum + "-" + secondNum + "=";
}
/**
* 随机3条1x以内数相减(借十法)
*
* @return
*/
public static List<String> randomThirdSubTopicList() {
List<String> result = new ArrayList<>();
while (result.size() < 3) {
String item = randomThirdSubTopic();
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成数一数题
*
* @return
*/
public static String randomComputeCountTopic() {
//四种图片
List<String> photoList = new ArrayList<>();
while (photoList.size() < 4) {
String photo = Photos.get(RandomUtil.randomInt(0, Photos.size()));
if (!photoList.contains(photo)) {
photoList.add(photo);
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < photoList.size(); i++) {
String photo = photoList.get(i);
int count = RandomUtil.randomInt(0, 7);
for (int j = 0; j < count; j++) {
sb.append(photo);
}
}
return sb + "_" + photoList.get(RandomUtil.randomInt(0, 4));
}
/**
* 随机4条随机生成数一数题
*
* @return
*/
public static List<String> randomComputeCountTopicList() {
List<String> result = new ArrayList<>();
while (result.size() < 4) {
String item = randomComputeCountTopic();
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 随机生成应用题
*
* @return
*/
public static String randomApplicationTopic() {
return ApplicationTopicList.get(RandomUtil.randomInt(0, ApplicationTopicList.size()));
}
/**
* 随机3条随机生成应用题题
*
* @return
*/
public static List<String> randomApplicationTopicList() {
List<String> result = new ArrayList<>();
while (result.size() < 3) {
String item = randomApplicationTopic();
if (!result.contains(item)) {
result.add(item);
}
}
return result;
}
/**
* 根据数量获取图片字符串
*
* @param photo
* @param count
* @return
*/
private static String getPhotoStr(String photo, int count) {
List<String> list = new ArrayList<>();
for (int i = 0; i < count; i++) {
list.add(photo);
}
return String.join("", list);
}
}
生成方法
/**
* 根据一段时间获取该段时间的所有月份
*
* @param minDate yyyy_MM_dd
* @param maxDate yyyy_MM_dd
* @return
*/
public static List<String> getDayBetween(String minDate, String maxDate) {
ArrayList<String> result = new ArrayList<String>();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd");
Calendar min = Calendar.getInstance();
Calendar max = Calendar.getInstance();
min.setTime(sdf.parse(minDate));
min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), min.get(Calendar.DAY_OF_MONTH));
max.setTime(sdf.parse(maxDate));
max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), max.get(Calendar.DAY_OF_MONTH));
Calendar curr = min;
while (curr.before(max)) {
result.add(sdf.format(curr.getTime()));
curr.add(Calendar.DAY_OF_MONTH, 1);
}
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
private static void generate(String path) throws Exception {
FileOutputStream out = new FileOutputStream(new File(path));
XWPFDocument document = new XWPFDocument();
//头部信息
createHeader(document);
createEmptyParagraph(document);
//第一大题 - 10以内的算术题
createNormalSumTopic(document);
createEmptyParagraph(document);
//第二大题 - 100以内的相邻数题
createNearNumTopic(document);
createEmptyParagraph(document);
//第三大题 - 100以内的比较大小题
createCompareTopic(document);
createEmptyParagraph(document);
//第四大题 - 10以内的分解组合题
createDivideCombinationTopic(document);
createEmptyParagraph(document);
//第五大题 - 10以内的图片计算题
createPhotoComputeTopic(document);
createEmptyParagraph(document);
createEmptyParagraph(document);
//第六大题 - 10以内的加法题(凑十法)
createSecondSumTopic(document);
createEmptyParagraph(document);
//第七大题 - 1x以内的减法题(借十法)
createThirdSubTopic(document);
createEmptyParagraph(document);
//第八大题 - 10以内的加减法连线题
createLinkTopic(document);
createEmptyParagraph(document);
//第九大题 - 数一数题
createComputeCountTopic(document);
createEmptyParagraph(document);
//第十大题 - 应用题
createApplicationTopic(document);
createEmptyParagraph(document);
document.write(out);
out.close();
}
/**
* 换行
*
* @param document
*/
private static void createEmptyParagraph(XWPFDocument document) {
//换行
XWPFParagraph spaceParagraph = document.createParagraph();
XWPFRun spaceParagraphRun = spaceParagraph.createRun();
spaceParagraphRun.setText("\r");
}
/**
* 创建头部信息
*
* @param document
*/
private static void createHeader(XWPFDocument document) {
//标题
XWPFParagraph titleParagraph = document.createParagraph();
titleParagraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun titleParagraphRun = titleParagraph.createRun();
titleParagraphRun.setText("暑假幼小衔接数学测试卷");
titleParagraphRun.setColor("000000");
titleParagraphRun.setFontSize(23);
titleParagraphRun.setFontFamily("宋体");
//分数
XWPFParagraph scoreParagraph = document.createParagraph();
scoreParagraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun scoreParagraphRun = scoreParagraph.createRun();
scoreParagraphRun.setText("(100分)");
scoreParagraphRun.setColor("000000");
scoreParagraphRun.setFontSize(17);
scoreParagraphRun.setFontFamily("楷体");
}
/**
* 创建第一大题 - 10以内的算术题
*
* @param document
*/
private static void createNormalSumTopic(XWPFDocument document) {
//20条10以内的算术题
List<String> topicList = randomNormalSumTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("一、看谁算得又对又快(10分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(4, 5);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 4;
int totalCol = 5;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum * totalCol + colNum;
String item = topicList.get(index);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
paragraphRun.setText(item);
paragraphRun.setColor("000000");
paragraphRun.setFontSize(17);
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第二大题 - 100以内的相邻数题
*
* @param document
*/
private static void createNearNumTopic(XWPFDocument document) {
//6条100以内的相邻数题
List<String> topicList = randomNearNumTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("二、填相邻数(6分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(2, 3);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 2;
int totalCol = 3;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum * totalCol + colNum;
String item = topicList.get(index);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
paragraphRun.setText(item);
paragraphRun.setColor("000000");
paragraphRun.setFontSize(17);
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第三大题 - 100以内的比较大小题
*
* @param document
*/
private static void createCompareTopic(XWPFDocument document) {
//6条100以内的相邻数题
List<String> topicList = randomCompareTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("三、在◯里填上“<”“>”或“=(8分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(2, 4);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 2;
int totalCol = 4;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum * totalCol + colNum;
String item = topicList.get(index);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
paragraphRun.setText(item);
paragraphRun.setColor("000000");
paragraphRun.setFontSize(17);
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第四大题 - 10以内的分解组合题
*
* @param document
*/
private static void createDivideCombinationTopic(XWPFDocument document) {
//8条10以内的分解组合题
List<String> topicList = TopicUtil.randomDivideCombinationTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("四、分解与组合(8分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable divideTable = document.createTable(3, 4);
divideTable.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
divideTable.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth divideTableWidth = divideTable.getCTTbl().addNewTblPr().addNewTblW();
divideTableWidth.setType(STTblWidth.DXA);
divideTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 3;
int totalCol = 4;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = colNum;
String item = topicList.get(index);
String[] itemArr = item.split("_");
XWPFTableRow row = divideTable.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.CENTER);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (rowNum % 3 == 0) {
paragraphRun.setText(itemArr[0]);
paragraphRun.setFontSize(17);
} else if (rowNum % 3 == 1) {
paragraphRun.setText("∧");
paragraphRun.setFontSize(43);
} else {
paragraphRun.setText(itemArr[1]);
paragraphRun.setFontSize(17);
}
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
createEmptyParagraph(document);
XWPFTable combinationTable = document.createTable(3, 4);
combinationTable.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
combinationTable.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth combinationTableWidth = combinationTable.getCTTbl().addNewTblPr().addNewTblW();
combinationTableWidth.setType(STTblWidth.DXA);
combinationTableWidth.setW(BigInteger.valueOf(9072));
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = 4 + colNum;
String item = topicList.get(index);
String[] itemArr = item.split("_");
XWPFTableRow row = combinationTable.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.CENTER);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (rowNum % 3 == 0) {
paragraphRun.setText(itemArr[0]);
paragraphRun.setFontSize(17);
} else if (rowNum % 3 == 1) {
paragraphRun.setText("∨");
paragraphRun.setFontSize(43);
} else {
paragraphRun.setText(itemArr[1]);
paragraphRun.setFontSize(17);
}
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第五大题 - 10以内的图片计算题
*
* @param document
*/
private static void createPhotoComputeTopic(XWPFDocument document) {
//4条10以内的图片计算题
List<String> topicList = randomPhotoComputeTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("五、看图列算式并计算(8分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(4, 2);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 4;
int totalCol = 2;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum;
String item = topicList.get(index);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (colNum % 2 == 1) {
paragraphRun.setText("□ ◯ □ = □");
} else {
paragraphRun.setText(item);
}
paragraphRun.setFontSize(17);
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第六大题 - 10以内的加法题(凑十法)
*
* @param document
*/
private static void createSecondSumTopic(XWPFDocument document) {
//3条10以内的加法题(凑十法)
List<String> topicList = randomSecondSumTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("六、算一算,凑十法(9分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(3, 3);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 3;
int totalCol = 3;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
String item = topicList.get(colNum);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.CENTER);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (rowNum == 0) {
paragraphRun.setText(item);
} else {
paragraphRun.setText("");
}
paragraphRun.setFontSize(17);
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第七大题 - 1x以内的减法题(借十法)
*
* @param document
*/
private static void createThirdSubTopic(XWPFDocument document) {
//3条10以内的加法题(凑十法)
List<String> topicList = randomThirdSubTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("七、算一算,借十法(9分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(3, 3);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 3;
int totalCol = 3;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum;
String item = topicList.get(colNum);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.CENTER);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (rowNum == 0) {
paragraphRun.setText(item);
} else {
paragraphRun.setText("");
}
paragraphRun.setFontSize(17);
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第八大题 - 10以内的加减法连线题
*
* @param document
*/
private static void createLinkTopic(XWPFDocument document) {
//5条10以内的加减法连线题
List<String> topicList = randomLinkTopicList();
List<String> answerList = new ArrayList<>();
for (int i = 0; i < topicList.size(); i++) {
answerList.add(topicList.get(i).split("=")[1]);
}
Collections.shuffle(answerList);
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("八、算一算,连一连(5分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(5, 2);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 5;
int totalCol = 2;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum;
String item = topicList.get(index);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.CENTER);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (colNum % 2 == 0) {
paragraphRun.setText(item.split("=")[0]);
} else {
paragraphRun.setText(answerList.get(rowNum));
}
paragraphRun.setFontSize(17);
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第九大题 - 数一数题
*
* @param document
*/
private static void createComputeCountTopic(XWPFDocument document) {
//4条数一数题
List<String> topicList = randomComputeCountTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("九、数一数,填一填(4分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(4, 2);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 4;
int totalCol = 2;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum;
String item = topicList.get(index);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.CENTER);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (colNum % 2 == 0) {
paragraphRun.setText(item.split("_")[0]);
} else {
paragraphRun.setText(item.split("_")[1] + "□个");
}
paragraphRun.setFontSize(17);
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
}
/**
* 创建第十大题 - 应用题
*
* @param document
*/
private static void createApplicationTopic(XWPFDocument document) {
//3条应用题
List<String> topicList = randomApplicationTopicList();
XWPFParagraph firstParagraph = document.createParagraph();
firstParagraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun firstParagraphRun = firstParagraph.createRun();
firstParagraphRun.setText("十、解决问题(15分)");
firstParagraphRun.setColor("000000");
firstParagraphRun.setFontSize(17);
firstParagraphRun.setFontFamily("楷体");
createEmptyParagraph(document);
//基本信息表格
XWPFTable table = document.createTable(6, 1);
table.setTableAlignment(TableRowAlign.CENTER);
//去表格边框
table.getCTTbl().getTblPr().unsetTblBorders();
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
int totalRow = 6;
int totalCol = 1;
for (int rowNum = 0; rowNum < totalRow; rowNum++) {
for (int colNum = 0; colNum < totalCol; colNum++) {
int index = rowNum / 2;
String item = topicList.get(index);
XWPFTableRow row = table.getRow(rowNum);
row.setHeight(800);
XWPFTableCell cell = row.getCell(colNum);
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); //垂直居中
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun paragraphRun = paragraph.createRun();
if (rowNum % 2 == 0) {
paragraphRun.setText(rowNum / 2 + 1 + "." + item);
} else {
paragraphRun.setText("");
}
paragraphRun.setFontSize(17);
paragraphRun.setColor("000000");
paragraphRun.setFontFamily("楷体");
}
}
}
4.使用
// List<String> dayList = getDayBetween("2023_07_01", "2023_09_01");
//
// for (int i = 0; i < dayList.size(); i++) {
// generate("/Users/geenju/Desktop/papers/" + dayList.get(i) + ".docx");
// }
for (int i = 1; i < 1000; i++) {
generate("/Users/geenju/Desktop/papers/幼小衔接测试题_" + i + ".docx");
}
网友评论