标签:
学习进度条:
点滴成就 | 学习时间 | 新编写代码行数 | 博客量(篇) | 学习知识点 |
第一周 | 10小时 | 0 | 0 | 了解软件工程 |
第二周 | 10小时 | 0 | 1 | 项目开题 |
第三周 | 15小时 | 0 | 1 | 开通博客、开展项目调查 |
第四周 | 20小时 | 200 | 1 | 需求文档、用例图、代码规范 |
第五周 | 15小时 | 0 | 0 | 软件工程 |
第六周 | 20小时 | 218 | 0 | 编译原理、软件工程详细设计 |
第七周 | 18小时 | 81 | 1 | 软件工程 |
1. 结对编程对象:胡磊 2013110410
对方博客地址:http://home.cnblogs.com/u/leihu/
双方贡献比例: 1:1
2. 源代码
package com.fancy.exam; import java.util.Random; public class Test { //一道四则运算题 private int number1; private int number2; private String sig; private int result; private String[] signal = {"+","-","*","/"}; public Test(){ Random rand = new Random(); int temp = rand.nextInt(4); this.sig = signal[temp]; this.number1 = rand.nextInt(100); this.number2 = rand.nextInt(100); if(this.sig.equals("/")){ if(this.number2 != 0){ //合法的除法运算 while(this.number1%this.number2!=0) { this.number1 = rand.nextInt(100); } }else{ //除数为零 this.number2 = rand.nextInt(100); } } switch(this.sig){ case "+": this.result = this.number1 + this.number2; break; case "-": this.result = this.number1 - this.number2; break; case "*": this.result = this.number1 * this.number2; break; case "/": this.result = this.number1 / this.number2; break; } } public int getNumber1() { return number1; } public void setNumber1(int number1) { this.number1 = number1; } public int getNumber2() { return number2; } public void setNumber2(int number2) { this.number2 = number2; } public String getSig() { return sig; } public void setSig(String sig) { this.sig = sig; } public int getResult() { return result; } public void setResult(int result) { this.result = result; } public void show(){ System.out.print(this.number1 + " " + this.number2 + " = " ); } }
package com.fancy.exam; public class Tests { //习题集类 private Test tests[]; private int count; //习题数目 public Tests(int count){ if(count>0){ this.count = count; } tests = new Test[count]; for(int i = 0;i<count;i++) tests[i] = new Test(); } public void printTests(){ //打印习题 for(int i=0;i<count;i++){ System.out.print(tests[i].getNumber1() + " " + tests[i].getSig() + " " + tests[i].getNumber2() + " =\t "); if((i+1)%5==0) System.out.println(); } } public void printAnswers(){ //打印答案 System.out.println("答案如下"); for(int i=0;i<count;i++){ System.out.print(tests[i].getNumber1() + " " + tests[i].getSig() + " " + tests[i].getNumber2() + " = " + tests[i].getResult() + " \t"); if((i+1)%5==0) System.out.println(); } } }
package com.fancy.exam; import java.util.Random; import java.util.Scanner; public class Tester { //测试类 public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int count; System.out.print("请输入题目数量:"); count = input.nextInt(); Tests tests = new Tests(count); tests.printTests(); System.out.println("是否打印答案?是:Y/y 不,直接退出:N/n"); String choice = input.next(); if(choice.equals("Y") || choice.equals("y")){ tests.printAnswers(); }else{ System.out.println("谢谢使用,再见。"); } input.close(); } }
3. 输入和输出
标签:
原文地址:http://www.cnblogs.com/FancyLian/p/5369691.html