首页 > 其他分享 >9.30课堂测试

9.30课堂测试

时间:2022-10-06 11:11:19浏览次数:50  
标签:9.30 int t2 System t1 break 测试 answer 课堂

没有使用栈来完成,不够简约,仍需改进。但是实现了继承和基本要求

2年纪类

package arith;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;

public class Arithmetics {

static int n1 = 30;
static int n3;
static double sumt=0;
static double sum=0;
ArrayList<Integer> Numbers = new ArrayList<>();
ArrayList<String> Symbols = new ArrayList<>();
ArrayList<Integer> Anwsers = new ArrayList<>();

static ArrayList<Integer> rNumbers = new ArrayList<>();
static ArrayList<String> rSymbols = new ArrayList<>();
static ArrayList<Integer> rAnwsers = new ArrayList<>();
//输入参数
public void getargu() {

int num1 = 30;
int num3 = 0;

Scanner sc = new Scanner(System.in);
System.out.println("请输入出题个数:");
num1 = sc.nextInt();

System.out.println("请输入操作数范围最大值:");
num3 = sc.nextInt();

n1=num1;
n3=argu(num3);

}
public int argu(int n3) {
if(n3>100) {
return 100;
}
else {
return n3;
}
}
//出题
public void draw(int nu1,int nu3) {

int s2 = 2;
Random rand = new Random();
Scanner sc = new Scanner(System.in);

int []numbers = new int[s2];
int []dsymbol = new int[s2-1];
String []symbols = new String[s2-1];

for(int i=0;i<nu1;i++) {
for(int j=0;j<s2;j++){
numbers[j] = rand.nextInt(nu3)+1;
}

for(int k=0;k<(s2-1);k++){
dsymbol[k] = rand.nextInt(4);
switch (dsymbol[k]) {
case 0:
symbols[k] = "+";
break;
case 1:
symbols[k] = "-";
break;
case 2:
symbols[k] = "*";
break;
case 3:
symbols[k] = "/";
break;
}
}
for(int e=0,t1=0,t2=0;e<s2*2;e++){
if(e%2==0){
Numbers.add(numbers[t1]);
t1++;
}
else if(e%2==1&&(e+1)%(s2*2)!=0){
Symbols.add(symbols[t2]);
if(symbols[t2]=="/") {
numbers[t2+1]=primefactor(numbers[t2]);
}
t2++;
}
else if(e%2==1&&(e+1)%(s2*2)==0) {
Symbols.add("=");
}
}
int answer = 0;
for(int e=0,t1=0,t2=0;e<s2;e++) {
if(e==0){
answer=answer+numbers[t1];
t1++;
}
else {

switch (symbols[t2]) {
case "+":
answer=answer+numbers[t1];
break;
case "-":
answer=answer-numbers[t1];
break;
case "*":
answer=answer*numbers[t1];
break;
case "/":
answer=answer/numbers[t1];
break;
}
t2++;
}

}
Anwsers.add(answer);
}
}
//判断正误
public boolean judge(int myanswer,int l){

if(Anwsers.get(l)==myanswer) {
return true;
}
else {
return false;
}

}
//做题
public void problem() {

Scanner sc = new Scanner(System.in);
int answer = 0;
int s2=2;
int s =0;
while(true) {
if(Symbols.get(s)=="=") {
s2=(s+1);
break;
}else {
s++;
}
}
for(int i=0;i<n1;i++) {
for(int j=0,t1=0,t2=0;j<100;j++) {
if(j%2==0) {
System.out.print(Numbers.get((i*s2)+t1));
t1++;
}
else if(j%2==1&&Symbols.get(t2)!="=") {
System.out.print(Symbols.get((i*s2)+t2));
t2++;
}
else if(j%2==1&&Symbols.get(t2)=="=") {
System.out.println(Symbols.get((i*s2)+t2));
t2++;
break;
}
}
answer = sc.nextInt();
if(judge(answer,i)) {
System.out.println("正确");
sumt++;
sum++;
}
else {
System.out.println("错误");
for(int e=0,t1=0,t2=0;e<s2*2;e++){
if(e%2==0){
rNumbers.add(Numbers.get((i*s2)+t1));
t1++;
}
else if(e%2==1){
rSymbols.add(Symbols.get((i*s2)+t2));
t2++;
}
}
rAnwsers.add(Anwsers.get(i));
sum++;
}
}

}
//错题集
public void wrongproblem() {
System.out.println("复习错题输入1");
System.out.println("查询正确率输入2");
Scanner sc = new Scanner(System.in);
int x1 = sc.nextInt();
if(x1==1) {
remake();
}else {
double rate;
rate = sumt/sum;
System.out.println(rate);
}
}
//重做
public void remake() {
Scanner sc = new Scanner(System.in);
int answer = 0;
int s2=2;
int s =0;
while(true) {
if(rSymbols.get(s)=="=") {
s2=(s+1);
break;
}else {
s++;
}
}
for(int i=0;i<n1;i++) {
for(int j=0,t1=0,t2=0;j<100;j++) {
if(j%2==0) {
System.out.print(rNumbers.get((i*s2)+t1));
t1++;
}
else if(j%2==1&&rSymbols.get(t2)!="=") {
System.out.print(rSymbols.get((i*s2)+t2));
t2++;
}
else if(j%2==1&&rSymbols.get(t2)=="=") {
System.out.println(rSymbols.get((i*s2)+t2));
t2++;
break;
}
}
answer = sc.nextInt();
if(judge(answer,i)) {
System.out.println("正确");
}
else {
System.out.println("错误");
}
}
}
//解决必须整除问题
public int primefactor(int n){
int m = 0;
if(n<1){
m= -1;
}
else if(n==1){
m= 1;
}
else {
while(n>1){
for(int i=2;i<=n;i++){
if (n==i){
m=n;
}
if(n%i==0){
n=n/i;
break;
}
}
}
}
return m;
}
}

3年级类,继承2年级

package arith;

import java.util.Random;
import java.util.Scanner;

public class Arithmetics3 extends Arithmetics{

public int argu(int n3) {
if(n3>1000) {
return 1000;
}
else {
return n3;
}
}
public void draw(int nu1,int nu3) {

int s2 = 4;
Random rand = new Random();
Scanner sc = new Scanner(System.in);

int []numbers = new int[s2];
int []dsymbol = new int[s2-1];
String []symbols = new String[s2-1];

for(int i=0;i<nu1;i++) {
for(int j=0;j<s2;j++){
numbers[j] = rand.nextInt(nu3)+1;
}

for(int k=0;k<(s2-1);k++){
dsymbol[k] = rand.nextInt(4);
switch (dsymbol[k]) {
case 0:
symbols[k] = "+";
break;
case 1:
symbols[k] = "-";
break;
case 2:
symbols[k] = "*";
break;
case 3:
symbols[k] = "/";
break;
}
}
for(int e=0,t1=0,t2=0;e<s2*2;e++){
if(e%2==0){
Numbers.add(numbers[t1]);
t1++;
}
else if(e%2==1&&(e+1)%(s2*2)!=0){
Symbols.add(symbols[t2]);
if(symbols[t2]=="/") {
numbers[t2+1]=primefactor(numbers[t2]);
}
t2++;
}
else if(e%2==1&&(e+1)%(s2*2)==0) {
Symbols.add("=");
}
}
int answer = 0;
for(int e=0,t1=0,t2=0;e<s2;e++) {
if(e==0){
answer=answer+numbers[t1];
t1++;
}
else {

switch (symbols[t2]) {
case "+":
answer=answer+numbers[t1];
break;
case "-":
answer=answer-numbers[t1];
break;
case "*":
answer=answer*numbers[t1];
break;
case "/":
answer=answer/numbers[t1];
break;
}
t2++;
}

}
Anwsers.add(answer);
}
}

}

4年级类,继承3年级

package arith;

import java.util.Random;
import java.util.Scanner;

public class Arithmetics4 extends Arithmetics3{

public int argu(int n3) {
return n3;
}
public void draw(int nu1,int nu3) {

int s2 = 5;
Random rand = new Random();
Scanner sc = new Scanner(System.in);

int []numbers = new int[s2];
int []dsymbol = new int[s2-1];
String []symbols = new String[s2-1];

for(int i=0;i<nu1;i++) {
for(int j=0;j<s2;j++){
numbers[j] = rand.nextInt(nu3)+1;
}

for(int k=0;k<(s2-1);k++){
dsymbol[k] = rand.nextInt(4);
switch (dsymbol[k]) {
case 0:
symbols[k] = "+";
break;
case 1:
symbols[k] = "-";
break;
case 2:
symbols[k] = "*";
break;
case 3:
symbols[k] = "/";
break;
}
}
for(int e=0,t1=0,t2=0;e<s2*2;e++){
if(e%2==0){
Numbers.add(numbers[t1]);
t1++;
}
else if(e%2==1&&(e+1)%(s2*2)!=0){
Symbols.add(symbols[t2]);
if(symbols[t2]=="/") {
numbers[t2+1]=primefactor(numbers[t2]);
}
t2++;
}
else if(e%2==1&&(e+1)%(s2*2)==0) {
Symbols.add("=");
}
}
int answer = 0;
for(int e=0,t1=0,t2=0;e<s2;e++) {
if(e==0){
answer=answer+numbers[t1];
t1++;
}
else {

switch (symbols[t2]) {
case "+":
answer=answer+numbers[t1];
break;
case "-":
answer=answer-numbers[t1];
break;
case "*":
answer=answer*numbers[t1];
break;
case "/":
answer=answer/numbers[t1];
break;
}
t2++;
}

}
Anwsers.add(answer);
}
}

}

主函数

package arith;

import java.util.Scanner;

public class Test1 {

public static void main(String[] args) {

Arithmetics ari2 = new Arithmetics();
Arithmetics ari3 = new Arithmetics3();
Arithmetics ari4 = new Arithmetics4();

for(int i=0;i!=1;) {
System.out.println("**************");
System.out.println(" 0. 终止 ");
System.out.println(" 1. 参数设置 ");
System.out.println("**************");
System.out.println(" 2.小学二年级口算题");
System.out.println(" 3.小学三年级口算题");
System.out.println(" 4.小学四年级口算题");
System.out.println(" 5. 错题集 ");
System.out.println("**************");
System.out.println("**输入1-5来选择**");
Scanner sc = new Scanner(System.in);
int a1 = sc.nextInt();
switch (a1) {
case 0:
i=1;
break;
case 1:
ari2.getargu();
break;
case 2:
ari2.draw(Arithmetics.n1,Arithmetics.n3);
ari2.problem();
break;
case 3:
ari3.draw(Arithmetics.n1,Arithmetics.n3);
ari3.problem();
break;
case 4:
ari4.draw(Arithmetics.n1,Arithmetics.n3);
ari4.problem();
break;
case 5:
ari2.wrongproblem();
break;
}
}

}

}

 

标签:9.30,int,t2,System,t1,break,测试,answer,课堂
From: https://www.cnblogs.com/rsy-bxf150/p/16757231.html

相关文章

  • python+selenium做ui自动化测试用法必会
    python+selenium做ui自动化测试用法必会一、前言大家都知道,基于Web端的测试的基础框架是需要Selenium做主要支撑的,这里边给大家介绍下Web测试核心之基于Python的Sele......
  • 性能测试jvm垃圾收集器G1和 CMS 的区别【杭州多测师】【杭州多测师_王sir】
    G1和CMS的区别平时工作中大多数系统都使用CMS,那么G1相对于CMS的区别在:1.G1在压缩空间方面有优势2.G1通过将内存空间分成区域(Region)的方式避免内存碎片问题3.......
  • 全功能测试框架 - Carina
    Carina是一个基于Java的测试自动化框架,它将所有测试层结合在一起:移动应用程序(web、本机、混合)、web应用程序、REST服务和数据库。github:https://github.com/zebrunner/ca......
  • 9/30课堂笔记及动手动脑
    类的定义:1、定义了一组大体上相似的对象。一个类所包含的方法和数据描述一组对象的共同行为和属性。2、对象则是类的具体化,是类的实例。3、类通过派生可以有子类,同样也......
  • 白盒测试学习
    视频链接:​​由浅入深学会白盒测试​​https://www.iqiyi.com/v_19rutfvny0.html#curid=10723543700_448c7137744e9f4a0cbd47d2f7771eea1、整体概念1.1、白盒测试特点:1.2、......
  • 15.7 os.path模块的常用方法_课堂案例 重要方法wark(path) 方法
     importos.pathprint('1.',os.path.abspath('demo13.py'))#获取文件或目录绝对路径print('2.',os.path.exists('demo13.py'),os.pa......
  • ping命令的多种玩法,以前竟然只用它来测试网速!
    作为开发人员,ping命令无疑是使用比较多的工具,我们经常在需要判断与服务器的连接是否连桶时需要使用ping命令来测试。【阅读全文】一般情况下使用ping命令来判断路由地址......
  • 跳过测试
         ......
  • 搭建appium自动化测试环境
    1.Java环境配置2.安装appium3.安装模拟器夜神模拟器,雷电模拟器启动模拟器 4.下载android-sdk-windows,放到任意盘,并配置环境变量     ......
  • 在PA2中学到的有关编写测试用例的经验补充
    来源:ysyx5期,PA2基础设施(2)- “测试你的klib”内存和字符串的写入函数,例如memset(), strcpy()等.内存和字符串的只读函数,例如memcmp(), strlen()等.格式化输出......