结对项目

 
点滴成就学习时间新编写代码行数博客量学到知识点
第一周1100了解软件工程
第二周1101了解软件工程
第三周1101用例图
第四周12250结对编程
第五周12301类图
第六周12600软件工程
第七周13401测试

package com.mindu.FourArithmeticOperations;

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

public class test {

static int standardAnswer;

public static void add(int addend1,int addend2){//加法
System.out.print(addend1 + "+" + addend2 + "=");
standardAnswer = addend1 + addend2;
}
public static void subtract(int minuend,int subtractor){//减法
if(minuend<subtractor){//减数大于被减数时交换
System.out.print(subtractor + "-" + minuend + "=");
standardAnswer = subtractor - minuend;
}
else{
System.out.print(minuend + "-" + subtractor + "=");
standardAnswer = minuend - subtractor;
}
}
public static void multiply(int multiplicator1,int multiplicator2){//乘法
System.out.print(multiplicator1 + "×" + multiplicator2 + "=");
standardAnswer = multiplicator1 * multiplicator2;
}
public static void divide(int dividend,int divisor){//除法
if(dividend<divisor||divisor == 0){//被除数小于除数或除数为0时两个交换
while(divisor%dividend>0){//有余数时进入循环
dividend--;
}
System.out.print(divisor + "÷" + dividend + "=");
standardAnswer = divisor / dividend;
}
else{
while(divisor%dividend>0){//有余数时进入循环
dividend--;
}
System.out.print(dividend + "÷" + divisor + "=");
standardAnswer = dividend / divisor;
}
}

public static void compared(int myAnswer,int standardAnswer){//判断是否为正确答案
if(myAnswer == standardAnswer){
System.out.println("做对啦!");
}
else{
System.out.println("做错啦!再接再厉!");
}
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Random random = new Random();
Scanner input=new Scanner(System.in);
int myAnswer;

System.out.print("请输入做题数量:");
int questionCount = input.nextInt();
System.out.println();

for(int i = 0;i<questionCount;i++){
int num1 = random.nextInt(101);//随机生成整数
int num2 = random.nextInt(101);
int index = random.nextInt(4);

System.out.print((i+1)+".");//题号

switch(index){
case 0://+
add(num1,num2);
myAnswer = input.nextInt();
compared(myAnswer,standardAnswer);
break;
case 1://-
subtract(num1,num2);
myAnswer = input.nextInt();
compared(myAnswer,standardAnswer);
break;
case 2://*
multiply(num1,num2);
myAnswer = input.nextInt();
compared(myAnswer,standardAnswer);
break;
case 3:// /
divide(num1,num2);
myAnswer = input.nextInt();
compared(myAnswer,standardAnswer);
break;
default:
break;
}
}
System.out.print("已经做完"+questionCount+"题咯!");
input.close();
}

}

运行截图:

转载于:https://www.cnblogs.com/minduu/p/5368410.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值