2015430 加法阶段一的封装测试

public class fdgfg
{
    Vector<Expression> v;
    public fdgfg()
    {
        v = new Vector<Expression>();
    }
    public void produceExpression(int bit,char operator)
    {
        Expression temp = new Expression();
        temp.operator = operator;
        temp.a = (int)(Math.random() * Math.pow(10,bit));
        temp.b = (int)(Math.random() * Math.pow(10,bit));
        switch (operator) 
        {
            case '+': temp.c = temp.a + temp.b;break;
            case '-': temp.c = temp.a - temp.b;break;
            case '*': temp.c = temp.a * temp.b;break;
            case '/': temp.b = (temp.b == 0 ? //排除除法被除数为0的情况
                      temp.b = 1 +(int)(Math.random() * Math.pow(10,bit)-1): temp.b);
                      temp.c = temp.a / temp.b;break;
            default : core(temp,bit);//封装混合运算测试
        }
 
        v.add(temp);
    }
    //混合运算的封装测试
    public void core(Expression temp,int bit)
    {
        int rand  = (int)(Math.random()*4);
        switch(rand)
        {
            case 1: temp.c = temp.a + temp.b;temp.operator = '+';break;
            case 2: temp.c = temp.a - temp.b;temp.operator = '-';break;
            case 3: temp.c = temp.a * temp.b;temp.operator = '*';break;
            case 0: temp.b = (temp.b == 0 ? //排除除法被除数为0的情况
                    temp.b = 1 +(int)(Math.random() * Math.pow(10,bit)-1): temp.b);
                    temp.c = temp.a / temp.b;temp.operator = '/';break;
            default :
        }
    }


任务分配: 29罗凯旋 完成阶段一的任务

伙伴 25廖灼燊 http://www.cnblogs.com/liaozhuoshen/p/4369428.html

posted @ 2015-04-30 16:35  29罗凯旋  阅读(166)  评论(2编辑  收藏  举报