结对编程——四则运算
2016-04-10 17:18
204 查看
题目:某公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道(100以内)四则运算题目给小学生做。
采用语言:Java
结对对象: 张莲 博客地址:http://home.cnblogs.com/u/linuoxin/
双方贡献比例:1:1
编程照片:
源代码:
package jiedui;
import java.util.Random;
import java.util.Scanner;
public class Jiedui {
public static void main(String[] args) {
// TODO Auto-generated method stub
double result1 = -1;// 正确的运算结果
double result2 = -1;// 用户输入的运算结果
// 循环30次,做30次运算
for (int i = 1; i <= 30; i++) {
System.out.println("第"+i+"题");
result1 = rightResult();
result2 = inputResult();
// 判断用户输入的答案是否正确
if (result1 == result2) {
System.out.println("恭喜你!答对了。");
} else {
System.out.println("噢~,答错了。");
System.out.println("正确答案为:" + result1);
}
}
}
public static double rightResult() {
int operand1 = -1;// 运算数1
int operand2 = -1;// 运算数2
int operation = -1;// 用于标记运算符:0为+,1为-,2为*,3为/
double result = -1;// 正确的运算结果
Random random = new Random();
operand1 = random.nextInt(100);// 随机生成在[0,100]范围内的运算数1
operand2 = random.nextInt(100);// 随机生成在[0,100]范围内的运算数2
operation = random.nextInt(3);// 随机生成运算符对应的序号:0为+,1为-,2为*,3为/
switch (operation) {
case 0: {
result = operand1 + operand2;
System.out.print(operand1 + "+" + operand2 + "=");// 输出题目
break;
}
case 1: {
result = operand1 - operand2;
System.out.print(operand1 + "-" + operand2 + "=");
break;
}
case 2: {
result = operand1 * operand2;
System.out.print(operand1 + "*" + operand2 + "=");
break;
}
case 3: {
if (operand2 == 0) {
operand2 = random.nextInt(99)+1;//运算数2重新生成1~100的数
}
result = operand1 / operand2;
System.out.print(operand1 + "/" + operand2 + "=");
break;
}
}
return result;
}
public static double inputResult() {
double result = -1;
Scanner input = new Scanner(System.in);
result = input.nextDouble();// 用户输入答案
return result;
}
}
运行结果:
总结:
结对编程让做题效率明显有效的提高,出错率降低,效果很好
学习进度条:
采用语言:Java
结对对象: 张莲 博客地址:http://home.cnblogs.com/u/linuoxin/
双方贡献比例:1:1
编程照片:
源代码:
package jiedui;
import java.util.Random;
import java.util.Scanner;
public class Jiedui {
public static void main(String[] args) {
// TODO Auto-generated method stub
double result1 = -1;// 正确的运算结果
double result2 = -1;// 用户输入的运算结果
// 循环30次,做30次运算
for (int i = 1; i <= 30; i++) {
System.out.println("第"+i+"题");
result1 = rightResult();
result2 = inputResult();
// 判断用户输入的答案是否正确
if (result1 == result2) {
System.out.println("恭喜你!答对了。");
} else {
System.out.println("噢~,答错了。");
System.out.println("正确答案为:" + result1);
}
}
}
public static double rightResult() {
int operand1 = -1;// 运算数1
int operand2 = -1;// 运算数2
int operation = -1;// 用于标记运算符:0为+,1为-,2为*,3为/
double result = -1;// 正确的运算结果
Random random = new Random();
operand1 = random.nextInt(100);// 随机生成在[0,100]范围内的运算数1
operand2 = random.nextInt(100);// 随机生成在[0,100]范围内的运算数2
operation = random.nextInt(3);// 随机生成运算符对应的序号:0为+,1为-,2为*,3为/
switch (operation) {
case 0: {
result = operand1 + operand2;
System.out.print(operand1 + "+" + operand2 + "=");// 输出题目
break;
}
case 1: {
result = operand1 - operand2;
System.out.print(operand1 + "-" + operand2 + "=");
break;
}
case 2: {
result = operand1 * operand2;
System.out.print(operand1 + "*" + operand2 + "=");
break;
}
case 3: {
if (operand2 == 0) {
operand2 = random.nextInt(99)+1;//运算数2重新生成1~100的数
}
result = operand1 / operand2;
System.out.print(operand1 + "/" + operand2 + "=");
break;
}
}
return result;
}
public static double inputResult() {
double result = -1;
Scanner input = new Scanner(System.in);
result = input.nextDouble();// 用户输入答案
return result;
}
}
运行结果:
总结:
结对编程让做题效率明显有效的提高,出错率降低,效果很好
学习进度条:
点滴成就 | 学习时间 | 新编写代码行数 | 博客量(篇) | 学到的知识点 |
第一周 | 2h | 0 | 0 | 了解认识软件工程 |
第二周 | 2h | 0 | 1 | 了解软件工程思想 |
第三周 | 2h | 0 | 1 | 制作并进行问卷调查 |
第四周 | 4h | 106 | 1 | 需求分析与结对编程 |
第五周 | 4h | 239 | 0 | Java的学习 |
第六周 | 3h | 0 | 0 | 初步学习“软件测试” |
第七周 | 4h | 106 | 1 | 软件系统设计、结对编程 |
相关文章推荐
- JavaWEB+Ajax实现文件上传
- two sum
- 代码空间项目 -- 获取当前时间之前的某一天-Calender类的使用
- LeetCode 206 -Reverse Linked List ( JAVA )
- 深入理解java虚拟机--线程安全与优化
- Spring中@Transactional用法深度分析之一
- C++11模板:如何判断类中是否有指定名称的成员变量?
- RxJava 常见误区(一):过度使用 Subject
- 夺命雷公狗---Thinkphp----5之数据库的链接
- 神级Win8.1 Update错误代码80073712为何令高手无语
- JAVA 内部类
- Python os模块
- Java中String类的方法及说明
- ASP.NET MVC4入门教程(六):验证编辑方法和编辑视图
- IntelliJ IDEA设置系列(五):类代码模板自定义(注释)
- C语言学习019:函数指针
- think python chapter3
- java封装示例代码
- 第一行代码 读笔④ (Fragment)
- 作业:C++作业3