学习进度条:
点滴成就 | 学习时间 | 新编写代码行数 | 博客量(篇) | 学习知识点 |
第一周 | 10小时 | 0 | 0 | 了解软件工程 |
第二周 | 10小时 | 0 | 1 | 项目开题 |
第三周 | 15小时 | 0 | 1 | 开通博客、开展项目调查 |
第四周 | 20小时 | 200 | 1 | 需求文档、用例图、代码规范 |
第五周 | 15小时 | 0 | 0 | 软件工程 |
第六周 | 20小时 | 291 | 0 | 编译原理、软件工程详细设计 |
第七周 | 18小时 | 91 | 1 | 软件工程 |
1、编程问题
某公司程序员二柱的小孩上了小学二年级,老师让家长每天出100道(100以内)四则运算题目给小学生做。
2、结对编程的出发点
为了体会结对编程的好处,和同伴一起相互学习,相互监督,相互促进,共同提高。
3、编程细节
(1). 结对编程对象:邹阳 2013110457
对方博客地址:http://home.cnblogs.com/u/Master-zy/
双方贡献比例: 1:1
(2). 源代码
package textFactory; /** * @function 检查合法性 * @author zy * */ public class CheckClass { /** * @function 检查一个(int)数字是否符合要求 * @param firstNum * @param maxNum * @param minNum * @return */ public static boolean checkNumIsOkOrNot(int Num, int maxNum, int minNum) { boolean result = false; if (Num >= minNum && Num <= maxNum) { result = true; } else { result = false; } return result; }// end /** * @function 检查一个(double)数字是否符合要求 * @param Num * @param maxNum * @param minNum * @return */ public static boolean checkNumIsOkOrNot(double Num, int maxNum, int minNum) { boolean result = false; if (Num >= minNum && Num <= maxNum) { result = true; } else { result = false; } return result; }// end /** * @function 检查一个字符串是否为整数 * @param value * @return */ public static boolean isInteger(String value) { try { Integer.parseInt(value); return true; } catch (NumberFormatException e) { return false; } }// end /** * @function检查运试算是否符合要求 * @param firstNum * @param secondNum * @param maxNum * @param minNum * @param answer * @param symbol * @return */ public static boolean checkTheTestIsOkOrNot(int firstNum, int secondNum, int maxNum, int minNum, double answer, char symbol) { boolean result = false; switch (symbol) { case '+': if (checkNumIsOkOrNot(answer, maxNum, minNum)) { result = true; } else { result = false; }// end if break; case '-': if (answer >= 0) { result = true; } else { result = false; } break; case '*': if (checkNumIsOkOrNot(answer, maxNum, minNum)) { result = true; } else { result = false; }// end if break; case '/': if (isInteger(String.valueOf(answer))) { result = true; } else { result = false; }// end if break; default: break; }// end switch return result; }// end }// end class package textFactory; import java.util.ArrayList; import java.util.Random; public class ArithmeticTest { int fistNum; int seconeNum; double answer; char symbol; ArrayList calcultorSymbol = new ArrayList(); public ArithmeticTest() { // TODO Auto-generated constructor stub }// end public ArithmeticTest(int fistNum, int seconeNum) { this.fistNum = fistNum; this.seconeNum = seconeNum; }// end public ArithmeticTest(int fistNum, int seconeNum, ArrayList calcultorSymbol) { super(); this.fistNum = fistNum; this.seconeNum = seconeNum; this.calcultorSymbol = calcultorSymbol; }// end /** * @function 获取小于 i 的随机数 * @param i * @return */ public static int getRandomNum(int i) { Random random = new Random(); int resNum; resNum = random.nextInt(i); return resNum; }// end /** * @function 随机获取一个运算符号 * @return */ public char getSymbol() { char symbol = '@'; int index = getRandomNum(this.calcultorSymbol.size()); symbol = (char) this.calcultorSymbol.get(index); return symbol; }// end /** * @function进行四则运算(无括号) * @param firstNum * @param secondNum * @param symbol */ public void calcAnswer(int firstNum, int secondNum) { this.symbol = getSymbol(); switch (symbol) { case '+': this.answer = firstNum + secondNum; break; case '-': this.answer = firstNum - secondNum; break; case '*': this.answer = firstNum * secondNum; break; case '/': this.answer = firstNum / secondNum; break; default: break; }// end switch }// end @Override public String toString() { // TODO Auto-generated method stub String resultTest = fistNum + " " + this.symbol + " " + seconeNum + " ="; return resultTest; }// end }// end class
package textFactory; import java.util.ArrayList; import org.omg.CORBA.TIMEOUT; import staticProperty.StaticPropertyStudy; /** * 算式测试与输出 * * @author zy * */ public class Tester { public static void main(String[] args) { int testNum = 30; int maxNum = 101; int minNum = 0; int firstNum; int secondNum; /* * 建立操作符列表 */ ArrayList symbolList = new ArrayList(); symbolList.add('+'); symbolList.add('-'); symbolList.add('*'); symbolList.add('/'); for (int i = 1; i <= testNum; i++) { boolean checkResult = true; while (checkResult) { ArithmeticTest arithmeticTest = null; firstNum = ArithmeticTest.getRandomNum(maxNum); secondNum = ArithmeticTest.getRandomNum(maxNum); // 创建一个运算式对象 arithmeticTest = new ArithmeticTest(firstNum, secondNum, symbolList); arithmeticTest.calcAnswer(arithmeticTest.fistNum, arithmeticTest.seconeNum); checkResult = CheckClass.checkTheTestIsOkOrNot(firstNum, secondNum, maxNum, minNum, arithmeticTest.answer, arithmeticTest.symbol); if (checkResult) { System.out.print("第 " + i + " 题: "); System.out.println(arithmeticTest); // System.out.println("答案是 --- >" + arithmeticTest.answer); System.out.println(); checkResult = false; } else { checkResult = true; }// end if }// end while }// end for }// end main }// end class
(3). 输入和输出
1)、没有答案的输出
2)、有答案的输出