标签:npe 最大 体会 blog action 运算符 mit you mat
https://github.com/2392030179/work.git
结伴同学:
黄观国 201606120075 https://www.cnblogs.com/666hll1212123/p/9865982.html
一、从个人项目出发,将程序改装成一个单机带用户界面(不是控制台)的程序,这个程序最基本要达到:
生成题目,单个题目最多不能超过4个运算符,操作数小于100。
用户可以输入答案
若用户输入答案正确,则提示正确;若答案错误,则提示错误,并要提示正确答案是多少。
二、下面附有 8 个相互独立的可以扩展的方向。
二、开发环境
工具:intellij idea
语言:java
三、分工
黄建科:
界面代码编写
黄观国:
核心算法功能
四、运行情况
五、总结
通过本次实验,对于界面设计掌握更为熟悉,同时也体会到了要做好一个界面不容易。
核心代码
public int question(){ Random random=new Random(); int ramNumber1=(int) (Math.random()*100); int ramNumber2=(int) (Math.random()*100); int ramNumber3=(int) (Math.random()*100); String[] operator={"+","-","*","/"}; int operatorIndex1=(int) (Math.random()*4); int operatorIndex2=(int) (Math.random()*4); int resultFirst=0; if (operatorIndex1<operatorIndex2){ resultFirst= arithmetic(ramNumber2,ramNumber3,operator[operatorIndex2]); resultLast= arithmetic(ramNumber1,resultFirst,operator[operatorIndex1]); } else { resultFirst= arithmetic(ramNumber1,ramNumber2,operator[operatorIndex1]); resultLast= arithmetic(resultFirst,ramNumber3,operator[operatorIndex2]); } // System.out.println(ramNumber1+operator[operatorIndex1]+ramNumber2+operator[operatorIndex2]+ramNumber3+"="); question=Integer.toString(ramNumber1)+operator[operatorIndex1]+Integer.toString(ramNumber2) +operator[operatorIndex2]+Integer.toString(ramNumber3)+"="; return resultLast; }
界面代码
public void mainFram(){ Container container=getContentPane(); setLayout(null); setBounds(100,100,1200,700); JButton setQuestion=new JButton("出题"); setQuestion.setFocusPainted(false); setQuestion.setBounds(350,310,100,50); setQuestion.setFont(new Font("宋体",Font.BOLD,20)); JButton submitAnswer=new JButton("提交"); submitAnswer.setFocusPainted(false); submitAnswer.setBounds(750,310,100,50); submitAnswer.setFont(new Font("宋体",Font.BOLD,20)); JTextField question=new JTextField(); question.setFont(new Font("宋体",Font.BOLD,50)); question.setBounds(350,0,500,250); JTextField answer=new JTextField(); answer.setFont(new Font("宋体",Font.BOLD,50)); answer.setBounds(350,260,500,50); JLabel jLabel=new JLabel("答题区:"); jLabel.setFont(new Font("宋体",Font.BOLD,50)); jLabel.setBounds(170,260,500,50); container.add(setQuestion); container.add(submitAnswer); container.add(question); container.add(answer); container.add(jLabel); setVisible(true); ariOperation=new AriOperation(); result=ariOperation.question(); question.setText(ariOperation.question); submitAnswer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String judge1="回答正确"; String judge2="回答错误,正确答案是:"+Integer.toString(result); if (Integer.parseInt(answer.getText()) == result) new Judge(judge1).setVisible(true); else new Judge(judge2).setVisible(true); } }); setQuestion.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ariOperation=new AriOperation(); result=ariOperation.question(); question.setText(ariOperation.question); } }); } }
标签:npe 最大 体会 blog action 运算符 mit you mat
原文地址:https://www.cnblogs.com/huangjianke123/p/9860721.html