开发环境:eclipse
结对同伴 :30 黎文衷
同伴博客:http://www.cnblogs.com/liwenzhong/
程序介绍:
1.第一阶段目标 - 把计算的功能封装成类。
2.设计测试用例:用白盒与黑盒测试设计技术,为计算核心设计测试用例。
3.在实验环境中(如MyEclipse集成开发环境+Junit测试框架)运行测试用例,分析测试结果,找出程序问题,给出改进前后的代码对照。
Calculator
1 public class Calculator { 2 3 public static void main(String[] args) { 4 int jia,jian,chen,chu,jiechen; 5 String fengshu1,fengshu2,fengshu3,fengshu4; 6 Zhengshu core1=new Zhengshu(); 7 core1.setJiaf(1, 1); 8 jia=core1.getSum(); 9 System.out.println(jia); 10 11 Zhengshu core2=new Zhengshu(); 12 core2.setJianf(1, 1); 13 jian=core2.getSum(); 14 System.out.println(jian); 15 16 Zhengshu core3=new Zhengshu(); 17 core3.setChengf(1, 1); 18 chen=core3.getSum(); 19 System.out.println(chen); 20 21 Zhengshu core4=new Zhengshu(); 22 core4.setChuf(1, 1); 23 chu=core4.getSum(); 24 System.out.println(chu); 25 26 Fenshu core5=new Fenshu(); 27 fengshu1=core5.answer(1, 2, 3, 4, 0); 28 System.out.println(fengshu1); 29 30 Fenshu core6=new Fenshu(); 31 fengshu2=core6.answer(1, 2, 3, 4, 1); 32 System.out.println(fengshu2); 33 34 Fenshu core7=new Fenshu(); 35 fengshu3=core7.answer(1, 2, 3, 4, 2); 36 System.out.println(fengshu3); 37 38 Fenshu core8=new Fenshu(); 39 fengshu4=core8.answer(1, 2, 3, 4, 3); 40 System.out.println(fengshu4); 41 42 Jiecheng core9=new Jiecheng(3); 43 jiechen=core9.getJieguo(); 44 System.out.println(jiechen); 45 46 } 47 48 }
整数core
1 public class Zhengshu { 2 int zs1,zs2,sum=1;int fh; 3 Zhengshu(){ 4 5 } 6 Zhengshu(int Zs1,int Fh,int Zs2){ 7 zs1=Zs1; 8 fh=Fh; 9 zs2=Zs2; 10 } 11 public void setJiaf(int Zs1,int Zs2){ 12 sum=Zs1+Zs2; 13 } 14 public void setJianf(int Zs1,int Zs2){ 15 sum=Zs1-Zs2; 16 } 17 public void setChengf(int Zs1,int Zs2){ 18 sum=Zs1*Zs2; 19 } 20 public void setChuf(int Zs1,int Zs2){ 21 sum=Zs1/Zs2; 22 } 23 public String getJiaf(){ 24 return zs1+"+"+zs2; 25 } 26 public String getJianf(){ 27 return zs1+"-"+zs2; 28 } 29 public String getChengf(){ 30 return zs1+"*"+zs2; 31 } 32 public String getChuf(){ 33 return zs1+"/"+zs2; 34 } 35 public int getSum(){ 36 return sum; 37 } 38 public String getsum(int zs1,int zs2){ 39 return zs1+"/"+zs2; 40 } 41 }
分数core
1 import java.util.Random; 2 3 4 public class Fenshu { 5 private int fz,fm;//用户输入分子、分母 6 private int fz0,fm0;//已约分正确分子、分母 7 private int fz1=1,fm1=1;//未约分正确分子、分母 8 private int jlfz,jlfm;//操作数 9 private int temp,ys;//操作数 10 private char ch; 11 private char fh[]={'+','-','*','/'}; 12 Fenshu(){} 13 public String suanshi(int a,int b,int c,int d,int z){ 14 if(a>b)//确保分母大于分子 15 { 16 temp=b; 17 b=a; 18 a=temp; 19 } 20 if(c>d)//确保分母大于分子 21 { 22 temp=d; 23 d=c; 24 c=temp; 25 } 26 // z=new Random().nextInt(cc*2-1); 27 return a+"/"+b+" "+fh[z]+" "+c+"/"+d; 28 29 } 30 public String answer(int a,int b,int c,int d,int z){ 31 if(a>b)//确保分母大于分子 32 { 33 temp=b; 34 b=a; 35 a=temp; 36 } 37 if(c>d)//确保分母大于分子 38 { 39 temp=d; 40 d=c; 41 c=temp; 42 } 43 int shu []=new int [4]; 44 shu[0]=a; 45 shu[1]=b; 46 shu[2]=c; 47 shu[3]=d; 48 switch(z) 49 { 50 case 0: 51 fz1=shu[0]*shu[3]+shu[1]*shu[2]; 52 fm1=shu[1]*shu[3]; 53 break; 54 case 1: 55 fz1=shu[0]*shu[3]-shu[1]*shu[2]; 56 fm1=shu[1]*shu[3]; 57 break; 58 case 2: 59 fz1=shu[0]*shu[2]; 60 fm1=shu[1]*shu[3]; 61 break; 62 case 3: 63 fz1=shu[0]*shu[3]; 64 fm1=shu[1]*shu[2]; 65 break; 66 default: 67 break; 68 } 69 jlfz=fz1;//约分 70 jlfm=fm1; 71 while(fm1!=0) 72 { 73 ys=fz1%fm1; 74 fz1=fm1; 75 fm1=ys; 76 } 77 fz0=jlfz/fz1; 78 fm0=jlfm/fz1; 79 if(fm0<0) 80 { 81 fz0=fz0*-1; 82 fm0=fm0*-1; 83 } 84 return fz0+"/"+fm0; 85 } 86 87 }
阶乘core
1 public class Jiecheng { 2 private int jc1; 3 private int sum=1; 4 private int n; 5 Jiecheng(){ 6 7 } 8 Jiecheng(int jc){ 9 jc1=jc; 10 11 } 12 public int getJieguo() 13 { 14 if(jc1==0) 15 sum=1; 16 else{ 17 for(n=1;n<=jc1;n++) 18 { 19 sum=sum*n; 20 } 21 } 22 return sum; 23 } 24 public int getsum() 25 { 26 return sum; 27 } 28 }
截图