• PSP----四则运算


    psp流程:

      预计耗时(分钟)实际耗时(分钟)
    Planning 计划 20 20
    Estimate 估计这个任务需要多少时间 90 90
    Development 开发 120 90
    Analysis 需求分析 10 10
    Design Spec 生成设计文档 / /
    Design Review 设计复审(和同事审核设计文档) / /
    Coding Standerd 代码规范(为目前的开发制定合适的规范) / /
    Design 具体设计 30 30
    Coding 具体编码 100 100
    Code Review 代码复审 10 15
    Text 测试(自测,修改代码,提交修改) 20 20
    Reporting 报告 20 20
    Text Report 测试报告 10 10
    Size Measurement 计算工作量 5 5
    Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 5 5
    Sum 合计 440 415

    代码:

      1 import javax.swing.*;
      2 import java.awt.*;
      3 import java.awt.event.*;
      4 public class sjcl {
      5     public static void main(String args[]) 
      6     {
      7         new Window();
      8     }
      9 }
     10 class Window extends JFrame 
     11 {
     12     /**
     13      * 
     14      */
     15     private static final long serialVersionUID = 1L;
     16     public  Window() 
     17     {
     18         setLayout(null);
     19         Container con = getContentPane();
     20         con.setBackground(new Color(168,229,73));
     21         setTitle("100以内的四则运算测试");
     22         init();
     23         setBounds(400,200,500,250);
     24         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     25         setVisible(true);
     26     }
     27     
     28     void init() 
     29     {
     30         //备注
     31         JLabel label = new JLabel();
     32         label.setText("除法四舍五入保留整数");
     33         label.setBounds(5,5,150,20);
     34         add(label);
     35         
     36         //获得题目
     37         int Numb_a,Numb_b,Numb_c;
     38         char[]c={'+','-','*','/'};
     39         Numb_c=(int)(1+Math.random()*3);
     40         Numb_a=(int)(1+Math.random()*100);
     41         Numb_b=(int)(1+Math.random()*100);
     42         String oper = " "+c[Numb_c]+" ";
     43         String t=Numb_a+oper+Numb_b;
     44 
     45         JButton GetQuestButton = new JButton("获得题目");
     46         JTextField GetQuestText = new JTextField();
     47         GetQuestButton.setBounds(80,30,100,30);
     48         GetQuestText.setBounds(180,30,200,30);
     49         GetQuestButton.addActionListener(new ActionListener(){
     50             public void actionPerformed(ActionEvent e) {                
     51                 GetQuestText.setText(t);
     52             }
     53         });
     54         add(GetQuestButton);
     55         add(GetQuestText);
     56         
     57         //确认答案
     58         JButton OutAnswerButton = new JButton("确认答案");
     59         JTextField OutAnswerText = new JTextField();
     60         add(OutAnswerButton);
     61         add(OutAnswerText);
     62         OutAnswerButton.setBounds(80,70,100,30);
     63         OutAnswerText.setBounds(180,70,200,30);
     64         OutAnswerButton.addActionListener(new ActionListener(){
     65             public void actionPerformed(ActionEvent e) {
     66                 int anwser=0;
     67                 if(c[Numb_c]=='+') {
     68                     anwser=Numb_a+Numb_b;
     69                 }
     70                 else if(c[Numb_c]=='-') {
     71                     anwser=Numb_a-Numb_b;
     72                 }
     73                 else if(c[Numb_c]=='*') {
     74                     anwser=Numb_a*Numb_b;
     75                 }
     76                 else if(c[Numb_c]=='/') {
     77                     anwser=(int)Math.rint(Numb_a/Numb_b);
     78                 }
     79                     
     80                 if(OutAnswerText.getText().equals(String.valueOf(anwser))){
     81                     JOptionPane.showMessageDialog(null, "回答正确!", "确认答案",JOptionPane.WARNING_MESSAGE);
     82                 }
     83                 else{
     84                     JOptionPane.showMessageDialog(null, "回答错误!", "确认答案",JOptionPane.ERROR_MESSAGE);
     85                 }
     86             }    
     87         });    
     88         
     89         //重置
     90         JButton ResetButton = new JButton("重置");
     91         add(ResetButton);
     92         ResetButton.setBounds(180,120,100,40);
     93         ResetButton.addActionListener(new ActionListener(){
     94             public void actionPerformed(ActionEvent e) {
     95                 new Window();
     96                 //GetQuestText.setText(null);
     97                 //OutAnswerText.setText(null);    
     98             }
     99         });
    100     }    
    101 }

     运行结果:

     

     

     

     

  • 相关阅读:
    决策树分类
    集群服务器 获取COOKIE错误
    React 自写Loading
    HTB-靶机-Unattended
    HTB-靶机-LaCasaDePapel
    HTB-靶机-FriendZone
    HTB-靶机-CTF
    HTB-靶机-FluJab
    HTB-靶机-Help
    HTB-靶机-Chaos
  • 原文地址:https://www.cnblogs.com/tantan0914/p/15345943.html
Copyright © 2020-2023  润新知