zoukankan      html  css  js  c++  java
  • 结对编程 计算器运算

    第三次作业   计算器
    需求分析:用户选择计算类型,然后由软件随机生成数据,然后用户给出运算结果,运算软件要判断是否正确,并在软件结束时显示统计结果。
    (1):做一个计算器窗口,添加上所有控件和运算符,便于用户输入和计算;
    public static void main(String[] args)
    { Frame frame = new Frame("计算器");
    frame.setSize(300, 200);
    frame.setLocation(300, 200);
    frame.addWindowListener(new Listener1());
    final TextField tf1 = new TextField(8);
    final Choice choice = new Choice();
    choice.addItem("+");
    choice.addItem("-"); choice.addItem("*");
    choice.addItem("/");
    final TextField tf2 = new TextField(8);
    Label label = new Label("=");
    final TextField tf3 = new TextField(8);
    Button button = new Button("计算");
    frame.add(tf1);
    frame.add(choice);
    frame.add(tf2);
    frame.add(label);
    frame.add(tf3);
    frame.add(button);
    frame.setLayout(new FlowLayout());
    button.addActionListener(new ActionListener()
    (2):写出运算公式
    public void actionPerformed(ActionEvent arg0)
    {String s1 = t
    f1.getText();
    String s2 = tf2.getText();
    String ch = choice.getSelectedItem();
    double d1 = Double.parseDouble(s1);
    double d2 = Double.parseDouble(s2);
    double d = 0;  
       if (ch.equals("+")){d = d1 + d2;
    } else if (ch.equals("-")){d = d1 - d2;
    } else if (ch.equals("*")){d = d1 * d2;
    } else     {d = d1 / d2;}tf3.setText(d + "");
    }
    });
    frame.setVisible(true);
    }
    }
    (3):最后加入一个计时器,但是没有运行出来;
    import java.io.IOException;
    public class Timer {public static void main(String[]args)
    {Timer timer = new Timer();
    timer.schedule(new MyTask(),1000,2000);
    while (true){try {int ch = System.in.read();
    if (ch-'c'==0){timer.cancel();
    }
    } catch (IOException e){e.printStackTrace();
    }
    }
    }private void cancel()
     {}
    private void schedule(MyTask myTask, int i, int j) 
    {}
    }
     
    总结:结对编程,不同于一个人编程,这里要有两个人的思维,一开始我们都很迷茫,慢慢的分析,有些思路后就彼此交流,如此反复,
    最后一起把程序作出来,感觉好吃力啊,毕竟能力有限,只能做到如此而已。。。
    合作图片:
    学号:1031
    姓名:刘云杰
    博客名:流星在天上
    博客链接:http://www.cnblogs.com/liuyunjie/p/4890526.html
    结对伙伴:郭冰清
  • 相关阅读:
    HDU 1002 大数A+B
    HDU 2066 一个人的旅行(最短路)
    HDU 1869 六度分离(最短路 floyd)
    HDU 1159 Common Subsequence(LCS)
    POJ 3061 Subsequence(尺取法)
    NYOJ 10 skiing(记忆化搜索)
    dedecms添加全站的rss订阅功能
    dedecms artlist读取全站最新文章
    dedecms的title怎么优化?
    DedeCMS提示Maximum execution time of 30 seconds exceeded in解决办法
  • 原文地址:https://www.cnblogs.com/liuyunjie/p/4890526.html
Copyright © 2011-2022 走看看