zoukankan      html  css  js  c++  java
  • 简单四则运算(PSP)

    任务要求
      小学生简单四则运算题库

    运行软件:
       Eclipse

    程序功能:
      能够输出100以内整数的四则运算题目,并且打印相应答案。

    代码:
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    import java.util.Scanner;
    import java.util.function.BiFunction;
    public class FourArithmetic {
    	private List<Subject> subjectList;
    	public List<Subject> getSubjectList() {
    		return subjectList;
    	}
    	public void setSubjectList(List<Subject> subjectList) {
    		this.subjectList = subjectList;
    	}
    	public FourArithmetic() {
    		System.out.print("输入题目数量
    ");
    		Scanner count = new Scanner(System.in);
    		int c = count.nextInt();
    		List<Subject> list = new ArrayList<Subject>();
    		BiFunction<Integer, Integer, Integer> sum = (x, y) -> x + y;
    		BiFunction<Integer, Integer, Integer> minus = (x, y) -> x - y;
    		BiFunction<Integer, Integer, Integer> multiple = (x, y) -> x * y;
    		BiFunction<Integer, Integer, Integer> divide = (x, y) -> x / y;
    		for (int i = 0; i < c; i++) { //题目数量
    			Subject subject = new Subject();
    			Integer a = new Random().nextInt(99);
    			Integer b = new Random().nextInt(99);
    			Float a1 = new Random().nextFloat();
    			Float b1 = new Random().nextFloat();
    			subject.setA(a);
    			subject.setB(b);
    			subject.setA1(a1);
    			subject.setB1(b1);
    			subject.setIndex(i + 1);
    			Integer symbol = new Random().nextInt(4);
    			if (symbol == 0) {
    				subject.setSymbol("+");
    				subject.setAnswer(sum.apply(a, b));
    			} else if (symbol == 1) {
    				subject.setSymbol("-");
    				subject.setAnswer(minus.apply(a, b));
    			} else if (symbol == 2) {
    				subject.setSymbol("×");
    				subject.setAnswer(multiple.apply(a, b));
    			} else if (symbol == 3) {
    				subject.setSymbol("÷");
    				subject.setAnswer(divide.apply(a, b));
    			}
    			list.add(subject);
    		}
    		this.subjectList = list;
    	}
    
    	public static void main(String[] args) {
    		FourArithmetic f = new FourArithmetic();
    		System.out.println("整数四则运算(除法保留整数位):");
    		f.getSubjectList().forEach(subject -> {
    			System.out.println("(" + subject.getIndex() + ") " + subject.getA() + subject.getSymbol()+subject.getB() + "= ?");
    		});
    		System.out.print("*******答案*******
    ");
            f.getSubjectList().forEach(subject -> {
        		System.out.println("第" + subject.getIndex() + "题:" + subject.getAnswer());
        	});
    	}
    }
    class Subject {
    	private Integer index;
    	private Integer a;
    	private Integer b;
    	private String symbol;
    	private Integer answer;
    	private Float a1;
    	private Float b1;
    	public Integer getIndex() {
    		return index;
    	}
    	public void setIndex(Integer index) {
    		this.index = index;
    	}
    	public Integer getA() {
    		return a;
    	}
    	public void setA(Integer a) {
    		this.a = a;
    	}
    	public Integer getB() {
    		return b;
    	}
    	public void setB(Integer b) {
    		this.b = b;
    	}
    	public void setB1(Float b1) {
    		this.b1 = b1;
    	}
    	public Float getB1() {
    		return b1;
    	}
    	public void setA1(Float a1) {
    		this.a1 = a1;
    	}
    	public Float getA1() {
    		return a1;
    	}
    	public String getSymbol() {
    		return symbol;
    	}
    	public void setSymbol(String symbol) {
    		this.symbol = symbol;
    	}
    	public Integer getAnswer() {
    		return answer;
    	}
    	public void setAnswer(Integer answer) {
    		this.answer = answer;
    	}
    }

      运行结果:

     









    psp2.1流程图

    PSP2.1

    Personal Software Process Stages

    预估耗时(分钟)

    实际耗时(分钟)

    Planning

    计划

    20

    20

    Estimate

    估计这个任务需要多少时间

    100

    100

    Development

    开发

    100

    90

    Analysis

    需求分析

    10

    10

    Design Spec

    生成设计文档

    /

    /

    Design Review

    设计复审 (和同事审核设计文档)

    /

    /

    Coding Standard

    代码规范 (为目前的开发制定合适的规范

    /

    /

    Design

    具体设计

    10

    10

    Coding

    具体编码

    150

    150

    Code Review

    代码复审

    60

    60

    Test

    测试(自我测试,修改代码,提交修改)

    80

    80

    Reporting

    报告

    5

    5

    Test Report

    测试报告

    5

    5

    Size Measurement

    计算工作量

    5

    5

    Postmortem& Process Improvement Plan

    事后总结, 并提出过程改进计划

    10

    10

    合计

     

    555

    545

  • 相关阅读:
    Struts系列教材 (十九)- 其他
    Struts系列教材 (十八)- 其他
    Struts系列教材 (十七)- 其他
    Struts系列教材 (十六)- 标签
    Struts系列教材 (十五)- 标签
    Struts系列教材 (十四)- 标签
    Struts系列教材 (十三)- 标签
    Struts系列教材 (十二)- 标签
    Struts系列教材 (十一)- 标签
    ios中二维码的使用之二: 二维码的扫描
  • 原文地址:https://www.cnblogs.com/Cute-pig/p/15345935.html
Copyright © 2011-2022 走看看