学习进度条

点滴成就 学习时间 新编写代码行数 博客量(篇) 学习知识点
第一周 2h 0 0 了解软件工程
第二周 3h 0 1 项目开题
第三周 5h 0 1 需求文档、用例图
第四周 8h 100 1 结对编程
第五周 12h 120 0 软件工程
第六周 15h 200 0 编译原理、软件工程详细设计
第七周 20h 100 1 软件测试

 

 

 

 

 

 

1. 结对编程对象:范心莲 2013110410

  对方博客地址:http://www.cnblogs.com/FancyLian/

   双方贡献比例: 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 + " = " );
    }
}
一道四则运算的类

相关文章:

  • 2021-06-12
  • 2021-05-30
  • 2021-10-08
  • 2021-08-07
  • 2022-02-27
猜你喜欢
  • 2021-12-25
  • 2021-10-20
  • 2022-02-08
  • 2021-11-26
  • 2021-08-16
  • 2021-05-02
  • 2021-07-31
相关资源
相似解决方案