修改后的出题系统

1.添加用户自定义是否出现乘除法,自由选择符号和个数,并且可以自定义操作数的取值范围。

  1 /*
2 * 2、可定制(数量/打印方式):输入大的数量值,测试一下系统是否崩溃,反向查找系统是否优化的余地;
3 3、定制操作数的个数:
4 4、定制是否有乘除法
5 5、定制是否有括号(随机加入)
6 6 、定制数值范围(确定操作数的取值范围)
7 */
8 package random;
9 import java.util.*;
10 import java.lang.reflect.Array;
11 import java.math.*;
12
13 public class Com {
14 @SuppressWarnings({ "unused", "unchecked" })
15 public static void main(String[] args) {
16 /*
17 * 定义数组存储每一次生成的随机数
18 *
19 */
20 ArrayList<ComDem> array1 = new ArrayList<ComDem>();
21 Scanner sc=new Scanner(System.in);
22 ComDem name1=new ComDem();
23 /*
24 * resu1 +
25 * resu2 -
26 * resu3 *
27 * resu4 /
28 * choice 定义随机产生的计算方法加减乘除
29 * choices 转换格式 switch
30 */
31 Random choice=new Random(1);
32 int choices;
33 /*
34 * 格式化输出 5列6行
35 * 定义 line
36 */
37 int line=0;
38 /*
39 * 控制操作数的范围
40 * max
41 * min
42 */
43 while(true) {
44 System.out.println("请依次输入操作数的最大值和最小值");
45 name1.max=sc.nextInt();
46 name1.min=sc.nextInt();
47 if(name1.max<=name1.min)
48 {
49 System.out.println("你输入的数据有误,最小值应该小于最大值!请重新输入:");
50 }
51 else
52 {
53 break;
54 }
55 }
56 Random rand1 =new Random(8);
57 Random rand2 =new Random(10);
58 Random rand3 =new Random(12);
59 name1.num1=rand1.nextInt(name1.max)+name1.min;
60 name1.num2=rand2.nextInt(name1.max)+name1.min;
61 name1.num3=rand3.nextInt(name1.max)+name1.min;
62 array1.add(name1);
63 int resu1,resu2,resu3;
64 double resu4;
65 /*
66 * 用户自定义打印题目数量
67 * 定义变量 printnum;
68 * 用户自定义是否有乘除法运算是否有带括号运算;
69 */
70 int printnum=0;
71 boolean isbrackets=false; //是否有括号
72 boolean isthree=true; //三个数还是两个数 true 3个 false 2个
73 boolean ismutiply=true; //是否有乘法 true有 false没有
74 boolean isdivide=true; //是否有除法 true有 false没有
75 System.out.println("题目是否要出现乘法:( true有 false没有,默认有)");
76 ismutiply=sc.nextBoolean();
77 System.out.println("题目是否要出现除法:( true有 false没有,默认有)");
78 isdivide=sc.nextBoolean();
79 System.out.println("请输入你要打印的题目数量:");
80 printnum=sc.nextInt();
81 System.out.println("(true 3个数的运算,false 2个数的运算)请输入你的选择");
82 isthree=sc.nextBoolean();
83 boolean flag=true; //查重标识
84 for(int i=0;i<printnum;i++)
85 {
86 /*
87 * 查重
88 */
89 for(int j=0; j<array1.size();j++) {
90 if(array1.get(j).num1==name1.num1|| array1.get(j).num2==name1.num2 ||
91 array1.get(j).num3==name1.num3)
92
93 {
94 name1.num1=rand1.nextInt(name1.max)+name1.min;
95 name1.num2=rand2.nextInt(name1.max)+name1.min;
96 name1.num3=rand3.nextInt(name1.max)+name1.min;
97 }
98 else
99 {
100 array1.add(name1);
101 flag=false;
102 }
103
104 if(flag==false)
105 break;
106 }
107 /*
108 * 两个数 + - * /
109 */
110 if(isthree==false && ismutiply==true && isdivide==true){
111 choices=choice.nextInt(4);
112 switch(choices) {
113 case 0:
114 System.out.print("("+(i+1)+")");
115 resu1=name1.add();
116 break;
117 case 1:
118 System.out.print("("+(i+1)+")");
119 resu2=name1.sub();
120 break;
121 case 2:
122 System.out.print("("+(i+1)+")");
123 resu3=name1.mix();
124 break;
125 case 3:
126 System.out.print("("+(i+1)+")");
127 resu4=name1.chu();
128 break;
129 }
130 }
131 /*
132 * 两个数乘法加减 * + -
133 */
134 if(isthree==false &&ismutiply==true&&isdivide==false){
135 choices=choice.nextInt(3);
136 switch(choices) {
137 case 0:
138 System.out.print("("+(i+1)+")");
139 resu1=name1.add();
140 break;
141 case 1:
142 System.out.print("("+(i+1)+")");
143 resu2=name1.sub();
144 break;
145 case 2:
146 System.out.print("("+(i+1)+")");
147 resu3=name1.mix();
148 break;
149 }
150 }
151 /*
152 * 两个数除法加减 / + -
153 *
154 */
155 if(isthree==false & ismutiply==false && isdivide==true){
156 choices=choice.nextInt(3);
157 switch(choices) {
158 case 0:
159 System.out.print("("+(i+1)+")");
160 resu1=name1.add();
161 break;
162 case 1:
163 System.out.print("("+(i+1)+")");
164 resu2=name1.sub();
165 break;
166 case 2:
167 System.out.print("("+(i+1)+")");
168 resu4=name1.chu();
169 break;
170 }
171 }
172 /*
173 * 两个数加减
174 */
175 if(isthree==false & ismutiply==false && isdivide==false){
176 choices=choice.nextInt(2);
177 switch(choices) {
178 case 0:
179 System.out.print("("+(i+1)+")");
180 resu1=name1.add();
181 break;
182 case 1:
183 System.out.print("("+(i+1)+")");
184 resu2=name1.sub();
185 break;
186 }
187 }
188 /*
189 * 三个数 + - * /
190 */
191 if(isthree==true&&ismutiply==true&&isdivide==true) {
192 choices=choice.nextInt(4);
193 switch(choices) {
194 case 0:
195 System.out.print("("+(i+1)+")");
196 resu1=name1.thereAdd();
197 break;
198 case 1:
199 System.out.print("("+(i+1)+")");
200 resu2=name1.therrSub();
201 break;
202 case 2:
203 System.out.print("("+(i+1)+")");
204 resu3=name1.threeMix();
205 break;
206 case 3:
207 System.out.print("("+(i+1)+")");
208 resu4=name1.threeChu();
209 break;
210 }
211 }
212 /*
213 * 三个数 乘法加减
214 */
215 if(isthree==true && ismutiply==true && isdivide==false)
216 {
217 choices=choice.nextInt(3);
218 switch(choices) {
219 case 0:
220 System.out.print("("+(i+1)+")");
221 resu1=name1.thereAdd();
222 break;
223 case 1:
224 System.out.print("("+(i+1)+")");
225 resu2=name1.therrSub();
226 break;
227 case 2:
228 System.out.print("("+(i+1)+")");
229 resu3=name1.threeMix();
230 break;
231 }
232 }
233
234 /*
235 * 三个数 除法加减
236 */
237 if(isthree==true && ismutiply==false && isdivide==true)
238 {
239 choices=choice.nextInt(3);
240 switch(choices) {
241 case 0:
242 System.out.print("("+(i+1)+")");
243 resu1=name1.thereAdd();
244 break;
245 case 1:
246 System.out.print("("+(i+1)+")");
247 resu2=name1.therrSub();
248 break;
249 case 2:
250 System.out.print("("+(i+1)+")");
251 resu4=name1.threeChu();
252 break;
253 }
254 }
255 /*
256 * 三个数 + - 只有加减
257 *
258 */
259 if(isthree==true && ismutiply==false && isdivide==false)
260 {
261 choices=choice.nextInt(2);
262 switch(choices) {
263 case 0:
264 System.out.print("("+(i+1)+")");
265 resu1=name1.thereAdd();
266 break;
267 case 1:
268 System.out.print("("+(i+1)+")");
269 resu2=name1.therrSub();
270 break;
271 }
272 }
273
274 /*
275 * 控制5个一换行
276 */
277 line++;
278 if(line>4 && line%5 ==0)
279 {
280 System.out.println();
281 }
282 /*
283 * 调用随机数函数;
284 */
285 name1.num1=rand1.nextInt(101);
286 name1.num2=rand2.nextInt(101);
287 name1.num3=rand3.nextInt(101);
288 sc.close();
289 }
290 }
291 }
292
 1 package random;
2 import java.util.*;
3 import java.math.*;
4 public class ComDem {
5 /*
6 * 定义几个操作数 完成运算
7 *
8 */
9 public int num1;
10 public int num2;
11 public int num3;
12 public int max;
13 public int min;
14 public int getNum3() {
15 return num3;
16 }
17 public void setNum3(int num3) {
18 this.num3 = num3;
19 }
20 public double getNum1() {
21 return num1;
22 }
23 public void setNum1(int num1) {
24 this.num1 = num1;
25 }
26 public double getNum2() {
27 return num2;
28 }
29 public void setNum2(int num2) {
30 this.num2 = num2;
31 }
32 public int getR1() {
33 num1=(int)(Math.random()*100);
34 return num1;
35 }
36 public int getR2() {
37 num2=(int)(Math.random()*100);
38 return num2;
39 }
40
41 /*
42 * 2 数运算
43 */
44 public int add() {
45 System.out.print(num1+"+"+num2+"="+"\t");
46 return num1+num2;
47 }
48 public int sub() {
49 System.out.print(num1+"-"+num2+"="+"\t");
50 return num1-num2;
51 }
52 public int mix() {
53 System.out.print(num1+"*"+num2+"="+"\t");
54 return num1*num2;
55 }
56 public double chu() {
57 System.out.print(num1+"/"+num2+"="+"\t");
58 return (double)(num1/num2);
59 }
60 /*
61 * 下面定义四个函数 分别是 + - * / 三个操作数的运算
62 *
63 */
64 public int thereAdd() {
65 System.out.print(num1+ "+" + num2 + "+" + num3 +"="+"\t");
66 return num1+num2+num3;
67 }
68 public int therrSub() {
69 System.out.print(num1+"-"+num2+"-" +num3+ "="+"\t");
70
71 return num1-(num2-num3);
72 }
73 public int threeMix() {
74 System.out.print(num1+"*"+num2+ "*"+num3+"="+"\t");
75 return num1*num2*num3;
76 }
77 public double threeChu() {
78 System.out.print(num1+"/"+num2+"/"+num3+"="+"\t");
79 return (num1/num2)/num3;
80 }
81 public ComDem(int num1, int num2,int num3){
82 this.num1 = num1;
83 this.num2 = num2;
84 this.num3 = num3;
85 }
86 ComDem(){};
87 }

JavaDailyReports10_04的更多相关文章

随机推荐

  1. PP-OCR论文翻译

    译者注: 我有逛豆瓣社区的习惯,因此不经意间会看到一些外文翻译成中文书的评价."书是好书,翻译太臭"."中文版别看"."有能力尽量看原版". ...

  2. IT人的5G网络架构视点:从网络架构演进的前世今生详解5G各NF网络功能体

    一.引言 以前从来没关注电信无线上网网络的具体架构(也即PS域架构),现在开始学5G接触这些东西时,理解起来很痛苦,资料也少,于是一方面到处找人咨询,一方面到处查资料,最后发现应该从3G.4G时代的架 ...

  3. PyQt(Python+Qt)学习随笔:QListWidget对项进行排序的sortItems方法

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QListWidget的sortItems方法用于对列表部件中所有项按参数进行排序,相关调用语法如下 ...

  4. Java基础学习之异常处理(6)

    @ 目录 1.异常是什么 1.1.Error 1.2.Exception 2.异常处理机制 2.1.捕获异常 2.2.抛出异常 3.自定义异常 3.1.自定义检查性异常 3.2.自定义运行时异常 1. ...

  5. 团队作业part2--需求规格说明书

    需求规格说明书 一.目的 本说明书为了让用户尽快了解产品所含功能,描述用户对产品的期望与需求.明确软件开发的最终目的,使开发出来的软件能够更好的达到用户的需求.其作为用户和软件开发人员达成的技术协议书 ...

  6. 题解-[SDOI2016]征途

    [SDOI2016]征途 [SDOI2016]征途 给定长度为 \(n\) 的序列 \(a\{n\}\),将其分为连续 \(m\) 段,和分别为 \(v\{m\}\).\(v\{m\}\) 的方差为 ...

  7. linux文件实时同步

    参考博客:https://www.cnblogs.com/MacoLee/p/5633650.html 一.文件同步很简单 服务端:被动的接收传输过来的数据 客户端:主动提供数据给服务端 安装思路:服 ...

  8. js日期格式化-----总结

    1. // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 ...

  9. Nginx安装配置教程

    转自https://www.cnblogs.com/zhouxinfei/p/7862285.html nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是 ...

  10. 【C#】DockPanelSuite 中 DockState.Document 状态下子窗体控件不显示的解决方案

    DockPanelSuite 是 Winform 中优秀的布局控件,但是这次使用过程中却出了个问题. 我遇到的问题是这样的,主窗体是通过 ShowDialog 显示的,子窗体的停靠状态为 DockSt ...