点滴成就 | 学习时间 | 新编写代码行数 | 博客量 | 学到知识点 |
第一周 | 8 | 0 | 0 | 知道软件工程是什么 |
第二周 | 7 | 0 | 1 | 分组,进行头脑风暴,介绍小组的项目 |
第三周 | 11 | 0 | 1 | 讨论项目的功能需求,画用例图,制作问卷,并回收,总结 |
第四周 | 6 | 25 | 0 | 写好需求文档,并体验结队编程. |
第五周 | 8 | 30 | 1 | 类图 |
第六周 | 11 | 60 | 0 | 软件测试 |
第七周 | 10 | 40 | 1 | 测试 |
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();
}
}
运行截图: