《小学四则运算练习软件》结对项目报告

源码在Github的仓库主页链接地址:https://github.com/feser-xuan/Arithmetic_test3_UI

小伙伴的博客链接:http://www.cnblogs.com/dwxuan/p/8711505.html

我的学号:201571030109

小伙伴的学号:201571030104

a. 需求分析:

(1)由计算机从题库文件中随机选择20道加减乘除混合算式,用户输入算式答案,程序检查答案是否正确,每道题正确计5分,错误不计分,20道题测试结束后给出测试总分;

(2)题库文件可采用实验二的方式自动生成,也可以手工编辑生成,文本格式如下:

(3)程序为用户提供三种进阶四则运算练习功能选择:百以内整数算式(必做)、带括号算式、真分数算式练习;

(4)程序允许用户进行多轮测试,提供用户多轮测试分数柱状图,示例如下:

(5)程序记录用户答题结果,当程序退出再启动的时候,可为用户显示最后一次测试的结果,并询问用户可否进行新一轮的测试;

(6)测试有计时功能,测试时动态显示用户开始答题后的消耗时间。

(7)程序人机交互界面是GUI界面(WEB页面、APP页面都可),界面支持中文简体(必做)/中文繁体/英语,用户可以进行语种选择。

b. 软件设计:使用类图。

c. 核心功能代码展示:展示核心功能代码。

(1)登录界面

 1 public class Login {
 2 
 3     public Login() 
 4     {
 5         JFrame f=new JFrame();
 6         f.setTitle("小学生四则运算答题系统");
 7         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 8         f.setExtendedState(JFrame.MAXIMIZED_BOTH);
 9         f.setVisible(true);
10         
11         //设置窗口的大小和位置
12         f.setSize(500,500);
13         f.setLocation(200,200);
14         
15         Container con=f.getContentPane();//生成一个容器    
16         con.setLayout(new GridLayout(7,1));
17         
18         JPanel pan1 =new JPanel();
19         JLabel title=new JLabel("欢迎登陆小学生四则运算答题系统");
20         title.setFont(new Font("宋体",Font.BOLD, 20));
21         pan1.add(title);
22         con.add(pan1);
23         //生成一个新的版      
24         JPanel pan2 = new JPanel();
25         JPanel pan3 = new JPanel();
26         JPanel pan4 = new JPanel();
27         JPanel pan5 = new JPanel();
28         
29         con.add(pan2);
30         con.add(pan3);    
31         con.add(pan4);
32         con.add(pan5);
33         
34         JLabel name=new JLabel("用户名");
35         pan2.add(name);
36         TextField tf_name=new TextField(20);
37         pan2.add(tf_name);
38         
39         JLabel pass = new JLabel("密码");
40         pan3.add(pass);
41         TextField password=new TextField(20);
42         password.setEchoChar('*');
43         pan3.add(password);
44         
45         JButton b_log=new JButton("登陆");  
46         b_log.addActionListener(new ActionListener() {  
47             public void actionPerformed(ActionEvent e) {  
48                 // TODO Auto-generated method stub  
49                 //获取用户名和密码,进行校验  
50                 String myUsername=tf_name.getText(); 
51                 String myPassword=password.getText();  
52                 if(myUsername.equals("admin")&& myPassword.equals("123456")){  
53                     JOptionPane.showMessageDialog(null, "登陆成功!");  
54                     f.dispose();
55                     new MyExGUI();
56                     
57                 }
58                 else{  
59                     JOptionPane.showMessageDialog(null, "账号或密码错误!");  
60                     name.setText( "");  
61                     password.setText( "");      
62                 }  
63                   
64             }  
65         });  
66         pan4.add(b_log); 
67         
68         JButton b_exit=new JButton("退出");       
69         b_exit.addActionListener(new ActionListener() {
70             public void actionPerformed(ActionEvent e) {
71                 // TODO Auto-generated method stub
72                  JOptionPane.showMessageDialog(null, "谢谢使用!");
73                  f.setVisible(false);//隐藏窗体
74                  System.exit(0);//退出程序
75             }        
76         });
77         pan5.add(b_exit);  
78         //登陆和退出这两个按钮放在第四个版面上
79         
80 
81     }
82 
83 }
View Code

(2)产生运算式的代码

  1 public class arithmetic 
  2 {
  3     ArrayList<String> list = new ArrayList<String>();
  4     ArrayList<String> list_timu = new ArrayList<String>();
  5     ArrayList<String> list_answer = new ArrayList<String>();
  6     public  arithmetic()
  7     {
  8             FileOutputStream outSTr = null;
  9             BufferedOutputStream Buff = null;
 10             int number_n=20,count;
 11             
 12             ArrayList<String> list_temp = new ArrayList<String>();
 13             String[] operator = new String[]{"+","-","*","/"};
 14             
 15             Random rand = new Random();
 16             File file1 = new File("result.txt");
 17             if (file1.exists()) {
 18                 // 创建文件
 19                 try {
 20                     file1.createNewFile();
 21                 } catch (IOException e) {
 22                     e.printStackTrace();
 23                 }
 24             }
 25             /*
 26             Scanner sb = new Scanner(System.in); 
 27             System.out.print("输入参数n:");
 28             try{
 29                 number_n = sb.nextInt();
 30             }catch(Exception e){
 31                 e.printStackTrace();
 32                 return;
 33             }
 34             */
 35             
 36             while(number_n>0)
 37             {
 38                 int[] number_temp = new int[rand.nextInt(2)+3];
 39                 String[] str_temp = new String[number_temp.length-1];
 40                 for(int i=0;i<number_temp.length;i++)
 41                 {
 42                     if(i<number_temp.length-1)
 43                     {
 44                         number_temp[i]=rand.nextInt(100);
 45                         list_temp.add(String.valueOf(number_temp[i]));
 46                         str_temp[i]=operator[rand.nextInt(4)];
 47                         list_temp.add(str_temp[i]);
 48                         
 49                     }
 50                             
 51                     else
 52                     {
 53                         number_temp[i]=rand.nextInt(100);
 54                         list_temp.add(String.valueOf(number_temp[i]));
 55                     }
 56                 }
 57                 
 58                 count=calculate_RPN(produce_RPN(list_temp));
 59                 if(count !=-1)
 60                 {
 61                     list_timu.add(transform_string(list_temp));
 62                     list_answer.add(String.valueOf(count));
 63                     list_temp.add(" = "+count);
 64                     list.add(transform_string(list_temp));
 65                     number_n--;
 66                     list_temp.clear();
 67                 }
 68                 else
 69                     list_temp.clear();
 70                 System.out.println(number_n);
 71                 
 72             }
 73             try {
 74             outSTr = new FileOutputStream(file1);
 75             Buff = new BufferedOutputStream(outSTr);
 76                 try {
 77                     Buff.write("201571030104  丁炜轩".getBytes());
 78                     Buff.write("\r\n".getBytes());
 79                 } catch (IOException e) {
 80                     e.printStackTrace();
 81                 }
 82                 for (int i = 0; i < list.size(); i++) 
 83                 {
 84                     try {
 85                         Buff.write(list.get(i).getBytes());
 86                         Buff.write("\r\n".getBytes());
 87                     } catch (IOException e) {
 88                         e.printStackTrace();
 89                         i--;
 90                     }
 91                 }
 92             Buff.flush();
 93             Buff.close();
 94             
 95             } catch (IOException e) {
 96                 e.printStackTrace();
 97             }
 98             //Buff.close();
 99             try {
100                 outSTr.close();
101             } catch (IOException e) {
102                 e.printStackTrace();
103             }
104            
105             for (int i = 0; i < list.size(); i++) 
106             {
107                 System.out.print(list.get(i));
108                 System.out.println();
109             }
110             System.out.print("计算完毕!");
111           
112         }
113         
114         public static int calculate_RPN(ArrayList<String> list_temp)
115         {
116             int i=0,t;
117             double a=0,b=0;
118             String l_temp;
119             Stack sk=new Stack(20);
120             for(t=0;t<list_temp.size();t++)
121             {
122                 l_temp = list_temp.get(i++);
123                 if(!isInteger(l_temp))
124                 {
125                     b = sk.mypop();
126                     a = sk.mypop();
127                     switch(l_temp)
128                     {
129                     case "+":sk.mypush(a+b);break;
130                     case "-":sk.mypush(a-b);break;
131                     case "*":sk.mypush(a*b);break;
132                     case "/":
133                         if(b==0)
134                             return -1;
135                         sk.mypush(a/b);break;
136                     }
137                     System.out.println("st.mytop: "+sk.mypeek());
138                 }
139                 else{
140                     sk.mypush((double)Integer.parseInt(l_temp));
141                 }
142                 
143             }
144             if(!sk.myisempty())
145             {
146                 a = sk.mypop();
147                 b = a-(int)a;
148                 System.out.println("a:  "+a);
149                 if(a>0 && b==0 )
150                 {
151                     return (int)a;
152                 }
153                 else
154                     return -1;
155             }
156             else
157                 return -1;
158             
159         }
160         
161         
162         public static ArrayList<String> produce_RPN(ArrayList<String> list_temp)
163         {
164             int t=0,i=0;
165             String tmp;
166             Tack mytack = new Tack(20);
167             ArrayList<String> lt_temp = new ArrayList<String>();
168             while(true)
169             {
170                 tmp = list_temp.get(i++);
171                 if(isInteger(tmp))
172                 {
173                     lt_temp.add(tmp);
174                 }
175                 else{
176                     if(mytack.myisempty())
177                     {
178                         mytack.mypush(tmp);
179                     }
180                         
181                     
182                     else{
183                         if(isCPriority(tmp, mytack.mypeek()))
184                             mytack.mypush(tmp);
185                         else{
186                             lt_temp.add(mytack.mypop());
187                             mytack.mypush(tmp);
188                         }
189                         
190                     }
191                 }
192                 if(i>=list_temp.size())
193                 {
194                     while(!mytack.myisempty())
195                         lt_temp.add(mytack.mypop());
196                     System.out.println(transform_string(list_temp));
197                     list_temp = lt_temp;
198                     System.out.println(list_temp);
199                     return list_temp;
200                 }
201             }
202             
203             
204         }
205         
206         
207         
208         public static boolean isInteger(String str) {    
209             for (int i = str.length();--i>=0;){  
210                         if (!Character.isDigit(str.charAt(i))){
211                             return false;
212                         }
213                     }
214                     return true;
215           } 
216         public static boolean isCPriority(String str,String s) { 
217             if((str+s).equals("*+") || (str+s).equals("*-") || (str+s).equals("/+") || (str+s).equals("/-"))
218                 return true;
219             else
220                 return false;    
221           }
222         public static String transform_string(ArrayList<String> list_temp)
223         {
224             String s="";
225             for(int i=0;i<list_temp.size();i++)
226             {
227                 s+=list_temp.get(i);
228             }
229             return s;
230             
231         }
232           
233         static class Stack
234         {
235             int mytop;
236             double stk[];
237             
238             public Stack(int num) {
239                 mytop=-1;
240                 stk=new double[num];
241             }
242             /*出栈*/
243             double mypop()
244             {
245                 double peek=stk[mytop];
246                 mytop--;
247                 return peek;
248             }
249             /*入栈*/
250             void mypush(double x)
251             {
252                 mytop++;
253                 stk[mytop]=x;
254                 
255             }
256             /*判空*/
257             Boolean myisempty()
258             {
259                 if(mytop==-1)
260                     return true;
261                 else
262                     return false;
263             }
264             /*取栈顶元素*/
265             double mypeek()
266             {
267                 double peek=stk[mytop];
268                 return peek;
269             }
270             /*栈大小*/
271             int mysize()
272             {
273                 return mytop+1;
274             }
275         }
276         
277         static class Tack
278         {
279             int mytop;
280             String tk[];
281             
282             public Tack(int num) {
283                 mytop=-1;
284                 tk=new String[num];
285             }
286             /*出栈*/
287             String mypop()
288             {
289                 String peek=tk[mytop];
290                 mytop--;
291                 return peek;
292             }
293             /*入栈*/
294             void mypush(String x)
295             {
296                 mytop++;
297                 tk[mytop]=x;
298                 
299             }
300             /*判空*/
301             Boolean myisempty()
302             {
303                 if(mytop==-1)
304                     return true;
305                 else
306                     return false;
307             }
308             /*取栈顶元素*/
309             String mypeek()
310             {
311                 String peek=tk[mytop];
312                 return peek;
313             }
314             /*栈大小*/
315             int mysize()
316             {
317                 return mytop+1;
318             }
319         
320 
321     }
322 
323 
324 }
View Code

(3)主要框架代码

  1 public class MyExGUI extends JFrame{
  2     ArrayList<String> user_zongti = new ArrayList<String>();
  3     ArrayList<String> user_zonganswer = new ArrayList<String>();
  4     ArrayList<String> user_answer = new ArrayList<String>();
  5     ArrayList<String> true_answer = new ArrayList<String>();
  6     ArrayList<String> jta_timu = new ArrayList<String>();
  7     ArrayList<String> jta_zong = new ArrayList<String>();
  8     ArrayList<Integer> user_fenshu = new ArrayList<Integer>();
  9     JMenuBar jmb;   //菜单条组件  
 10     JMenu menu1, menu2, menu3, menu4, menu5;//菜单  
 11     JMenuItem item1, item2, item3, item4, item5, item6;//菜单项  
 12     JMenu build;    //二级菜单  
 13     JMenuItem file, project; 
 14     TextArea answer_all = new TextArea();
 15     TextField jta = new TextField();
 16     TextField jta_answer = new TextField(); 
 17     JLabel num_answer = new JLabel();
 18     JLabel answer1;
 19     JToolBar jtb;//工具条  
 20     JButton jb1, jb2, jb3, jb4, jb5, jb6, jb7,jb_next;  
 21     int answer_count;
 22     int answer_fenshu;
 23     public MyExGUI()
 24     {  
 25         //创建菜单  
 26         jmb = new JMenuBar();  
 27         
 28         menu1 = new JMenu("文件(F)");  
 29         menu1.setMnemonic('f'); //助记符  
 30         menu2 = new JMenu("编辑");  
 31         menu2.setMnemonic('E');  
 32         menu3 = new JMenu("格式");  
 33         menu4 = new JMenu("查看");  
 34         menu5 = new JMenu("帮助");  
 35           
 36         build = new JMenu("新建");  
 37           
 38         file = new JMenuItem("文件");  
 39         project = new JMenuItem("答题");  
 40         item1 = new JMenuItem("打开");  
 41         item2 = new JMenuItem("保存(S)");  
 42         item3 = new JMenuItem("另存为");  
 43         item4 = new JMenuItem("页面设置");  
 44         item5 = new JMenuItem("打印");  
 45         item6 = new JMenuItem("退出");  
 46         
 47         answer1 = new JLabel("第 1 题");
 48        
 49         
 50           
 51             //添加菜单项至菜单上  
 52         build.add(file);  
 53         build.add(project);  
 54           
 55         menu1.add(build);  
 56         menu1.add(item1);  
 57         menu1.add(item2);  
 58         menu1.add(item3);  
 59         menu1.addSeparator();  
 60         menu1.add(item4);  
 61         menu1.add(item5);  
 62         menu1.add(item6);  
 63             //将菜单加入至菜单栏  
 64         jmb.add(menu1);  
 65         jmb.add(menu2);  
 66         jmb.add(menu3);  
 67         jmb.add(menu4);  
 68         jmb.add(menu5);  
 69           
 70         
 71         JPanel contentPanel = new JPanel();
 72         contentPanel.setLayout(null);
 73         JLabel daan = new JLabel("答案");
 74         JLabel dengyu = new JLabel("=");
 75         num_answer=answer1;
 76         num_answer.setFont(new Font("宋体",Font.BOLD, 22));
 77         jb_next = new JButton("下一题");
 78         jta.setFont(new Font("宋体",Font.BOLD, 22));
 79         jta_answer.setFont(new Font("宋体",Font.BOLD, 22));
 80         jb_next.setFont(new Font("宋体",Font.BOLD, 22));
 81         daan.setFont(new Font("宋体",Font.BOLD, 22));
 82         dengyu.setFont(new Font("宋体",Font.BOLD, 22));
 83         
 84         contentPanel.add(num_answer);
 85         contentPanel.add(daan);
 86         contentPanel.add(dengyu);
 87         contentPanel.add(jta);
 88 
 89         contentPanel.add(jta_answer);
 90         contentPanel.add(answer_all);
 91         contentPanel.add(jb_next);
 92         
 93         num_answer.setBounds(90, 20, 130, 50);
 94         daan.setBounds(250, 20, 90, 50);
 95         jta.setBounds(50, 70, 150, 30);
 96         dengyu.setBounds(205, 70, 20, 20);
 97         jta_answer.setBounds(230, 70, 100, 30);
 98         jb_next.setBounds(350, 70, 110, 30);
 99         answer_all.setBounds(50, 120, 400, 300);
100         
101         this.setJMenuBar(jmb);  //添加菜单栏,不能设定位置,会自动放在最上部  
102         this.add(contentPanel);
103         
104         this.setTitle("在线答题系统");  
105         this.setSize(600, 500);  
106         this.setVisible(true);  
107         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
108         item1.addActionListener(new ActionListener() {
109             
110             @Override
111             public void actionPerformed(ActionEvent arg0) {
112                 // TODO Auto-generated method stub
113                 JFileChooser jfc=new JFileChooser();                        
114                 jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );  
115                 jfc.showDialog(new JLabel(), "选择");  
116                 File file=jfc.getSelectedFile();  
117                 if(file.isDirectory()){  
118             //  System.out.println("文件夹:"+file.getAbsolutePath()); 
119                 }else if(file.isFile()){  
120                     String s=file.getAbsolutePath();  
121                 }    
122             }
123         });
124         item2.addActionListener(new ActionListener() {
125             
126             @Override
127             public void actionPerformed(ActionEvent arg0) {
128                 FileOutputStream outSTr = null;
129                 BufferedOutputStream Buff = null;
130                 boolean flag = true;
131                 File file;
132                 //String test ;
133                 do{
134                     //test = "test"+count;
135                 
136                     String inputValue = JOptionPane.showInputDialog("Please input file name"); 
137                     file = new File(inputValue+".txt");
138                     if (!file.exists()) {
139                         // 创建文件
140                         try {
141                             //System.out.println("文件夹:"+flag); 
142                             flag=file.createNewFile();
143                             //System.out.println("文件夹:"+flag); 
144                         } catch (IOException e) {
145                             e.printStackTrace();
146                             //JOptionPane.showMessageDialog(null, "ERROR", "该文件名已存在,请重新输入", JOptionPane.ERROR_MESSAGE);
147                         }
148                         flag=false;
149                     }
150                     else{
151                         
152                         JOptionPane.showMessageDialog(null, "该文件名已存在,请重新输入", "ERROR", JOptionPane.ERROR_MESSAGE);
153                         flag=true;
154                     }
155                 }while(flag);
156                 //写入文件
157                 String u_answer;
158                 try {
159                     outSTr = new FileOutputStream(file);
160                     Buff = new BufferedOutputStream(outSTr);
161                     System.out.println("选择是后执行的代码"+user_zongti.size()+user_answer.size()); 
162                         for (int i = 0; i < user_zongti.size(); i++) 
163                         {
164                             try {
165                                 Buff.write(user_zongti.get(i).getBytes());
166                                 Buff.write("    ".getBytes());
167                                 u_answer = user_answer.get(i);
168                                 if(u_answer.equals(""))
169                                     u_answer ="没有作答";
170                                 
171                                 Buff.write(u_answer.getBytes());
172                                 Buff.write("\r\n".getBytes());
173                             } catch (IOException e) {
174                                 e.printStackTrace();
175                                 i--;
176                             }
177                         }
178                     Buff.flush();
179                     Buff.close();
180                     
181                     } catch (IOException e) {
182                         e.printStackTrace();
183                     }
184                     //Buff.close();
185                     try {
186                         outSTr.close();
187                     } catch (IOException e) {
188                         e.printStackTrace();
189                     }
190                     user_zongti.clear();
191                     user_answer.clear();
192             }
193         });
194         
195         
196         project.addActionListener(new ActionListener() {
197             
198             @Override
199             public void actionPerformed(ActionEvent arg0) {
200                 arithmetic art = new arithmetic();
201                 true_answer=art.list_answer;
202                 jta_timu = art.list_timu;
203                 jta_zong = art.list;
204                 answer_count=1;
205                 answer_all.setText("");
206                 for (int i = 0; i < art.list_timu.size(); i++)
207                 {
208                     user_zongti.add(jta_zong.get(i));
209                     answer_all.append(jta_timu.get(i));
210                     answer_all.append("\r\n");
211                 }
212                 num_answer.setText("第 "+answer_count+" 题");    
213                 jta.setText(jta_timu.get(answer_count-1));
214                 answer_count++;
215                 
216                 
217             }
218         });
219         jb_next.addActionListener(new ActionListener() {
220             
221             @Override
222             public void actionPerformed(ActionEvent arg0) {
223                 String temp;
224                 temp = jta_answer.getText();
225                 
226                 if(jta.getText().equals(""))
227                 {
228                     JOptionPane.showMessageDialog(null, "错误,请导入题库", "错误", JOptionPane.ERROR_MESSAGE);
229                     return;
230                 }
231                 jta_answer.setText("");
232                 if(answer_count<=20)
233                 {
234                     if(isInteger(temp))
235                     {
236                           
237                         user_answer.add(temp);
238                         System.out.println("选择否后执行的代码"+temp+"user_size"+user_answer.size());
239                         num_answer.setText("第 "+answer_count+" 题");    
240                         jta.setText(jta_timu.get(answer_count-1));
241                         answer_count++;
242                     }
243                     else{
244                         JOptionPane.showMessageDialog(null, "错误", "请输入数字", JOptionPane.ERROR_MESSAGE);
245                     }
246                 }
247                 else{
248                     user_answer.add(temp);
249                     System.out.println("选择否后执行的代码"+temp+"user_size"+user_answer.size());
250                     answer_fenshu=0;
251                     for(int i=0;i<user_answer.size();i++)
252                     {
253                         if(user_answer.get(i).equals(true_answer.get(i)))
254                             answer_fenshu+=5;
255                     }
256                     user_fenshu.add(answer_fenshu);
257                     Object[] options = { "是", "取消" }; 
258                     int res=JOptionPane.showOptionDialog(null, "点击以继续 查看成绩", "答题完毕", 
259                     JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION, 
260                     null, options, options[0]); 
261                     if(res==JOptionPane.YES_OPTION){
262                         chart ct =new chart(user_fenshu);
263                         ct.setVisible(true);
264                         //ct.paint(Graphics g);
265                         //System.out.println("选择是后执行的代码");    //点击“是”后执行这个代码块
266                     }else{
267                         Object[] option = { "是", "取消" }; 
268                         int res1=JOptionPane.showOptionDialog(null, "继续新一轮答题", "新一轮答题", 
269                         JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION, 
270                         null, option, option[0]); 
271                         //System.out.println("选择否后执行的代码");    //点击“否”后执行这个代码块
272                         if(res1==JOptionPane.YES_OPTION){
273                             arithmetic art = new arithmetic();
274                             true_answer=art.list_answer;
275                             //jta_timu = art.list_timu;
276                             jta_timu = art.list;
277                             answer_count=1;
278                             answer_all.setText("");
279                             jta_answer.setText("");
280                             for (int i = 0; i < art.list_timu.size(); i++)
281                             {
282                                 user_zongti.add(jta_timu.get(i));
283                                 answer_all.append(jta_timu.get(i));
284                                 answer_all.append("\r\n");
285                             }
286                             num_answer.setText("第 "+answer_count+" 题");    
287                             jta.setText(jta_timu.get(answer_count-1));
288                             answer_count++;
289                             //System.out.println("选择是后执行的代码");    //点击“是”后执行这个代码块
290                         }else{
291                             
292                         }
293                         
294                     } 
295                     
296                     
297                     
298                 }
299                 
300                 
301                 
302             }
303         });
304         
305         
306         
307         
308     }
309     
310     public static boolean isInteger(String str) {    
311         for (int i = str.length();--i>=0;){  
312                     if (!Character.isDigit(str.charAt(i))){
313                         return false;
314                     }
315                 }
316                 return true;
317       } 
318     
319     
320     
321     
322 }
View Code

(4)产生柱状图的代码

 1 import java.awt.Color;  
 2 import java.awt.Graphics;  
 3 import java.awt.Graphics2D;
 4 import java.util.ArrayList;
 5 import java.util.Random;  
 6   
 7 import javax.swing.JFrame;
 8   
 9 public class chart extends JFrame{
10       //绘制柱形统计图  
11         ArrayList<Integer> ran=new  ArrayList<Integer>();
12         public chart(ArrayList<Integer> scores)
13         {  
14             super();  
15             getContentPane().setForeground(Color.CYAN);
16             setForeground(Color.CYAN);
17             setBackground(Color.CYAN);
18             for(int i=0;i<scores.size();i++)
19             {
20                 ran.add(scores.get(i));
21                 System.out.println(scores.get(i));
22             }
23               
24             setTitle("绘制柱形图");  
25             setSize(600, 400);
26             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
27         }  
28         @Override  
29         public void paint(Graphics g){
30             int Width = getWidth();
31             int Height = getHeight();
32             int leftMargin = 20;//柱形图左边界
33             int topMargin = 50;//柱形图上边界
34             Graphics2D g2 = (Graphics2D) g;
35             g2.setColor(Color.WHITE);//绘制白色背景
36             g2.fillRect(0, 0, Width, Height-100);//绘制矩形图
37             g2.setColor(Color.black);
38              for(int i=0;i<=10;i++)
39              {
40                  //绘制灰色横线和百分比
41                  g2.drawString((100-10*i)+"", 15, topMargin+30*i);
42                  g2.drawLine(5, topMargin+30*i, Width, topMargin+30*i);//绘制灰色横线
43              }
44              g2.setColor(Color.YELLOW);
45              for(int i=0;i<=ran.size();i++)
46              {
47                  //绘制柱形图
48                  int step = (i+1)*40;//设置每个柱形图的水平间隔为40
49                  //绘制矩形
50                  g2.fillRoundRect(leftMargin+step*2-5,(100-ran.get(i))*3+50, 40, 300-(100-ran.get(i))*3, 40, 10);
51                  //列出测试轮数
52                  g2.drawString("第"+(i+1)+"轮", leftMargin+step*2, 380);
53              }    
54          }  
55 
56     
57 }  
View Code

(5)主函数的代码

1 public class Main {
2 
3     public static void main(String[] args) {
4         new Login();
5 //        new MyExGUI();
6 
7     }
8 
9 }
View Code

d. 程序运行:程序运行时每个功能界面截图。

(1)登录界面,登录用户名“admin”,密码123456

(2)答题界面,点击文件---答题,则开始答题

 

(3)一轮结束后,选择查看成绩,显示柱状图

(4)点击保存按钮,跳出对话框,输入文件名,就可在根目录下看到文件。

e.描述结对的过程,提供两人在讨论、细化和编程时的结对照片(非摆拍)。

f.提供此次结对作业的PSP。

PSP2.1

任务内容

计划共完成需要的时间(min)

实际完成需要的时间(min)

Planning

计划

120

150

·       Estimate

·  估计这个任务需要多少时间,并规划大致工作步骤

80

100

Development

开发

800

600

··       Analysis

  需求分析 (包括学习新技术)

     100     80

·       Design Spec

·  生成设计文档

60

60

·       Design Review

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

40

30

·       Coding Standard

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

60

50

·       Design

  具体设计

240

200

·       Coding

  具体编码

600

700

·       Code Review

·  代码复审

60

70

·       Test

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

240

212

Reporting

报告

120

140

··       Test Report

·  测试报告

30

25

·       Size Measurement

  计算工作量

30

30

·       Postmortem & Process Improvement Plan

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

30

20

g. 请使用汉堡评价法给你的小伙伴一些点评。

         我的小伙伴是丁炜轩,他很认真,对待每一件事都有一个积极的态度,在这次结对编程中,承担主要的工作量,如果他是赛车手,我就是导航员,如果他是狙击手,我就是观察员,如果他是机长,我就是副机长,我们相辅相成,缺一不可。在生活中,我的小伙伴是我的室友,我对他也有一个比较全面的了解,他的工作能力强,有责任心,对待事物和热情。在这次编程中,我们两个都提出了建设性的意见。在这次编程中,我们两个都提出了建设性的意见,互相修改代码,虽然有些争执,但是还是很好的解决了,完成了这次编程任务。

h. 结对编程真的能够带来1+1>2的效果吗?通过这次结对编程,请谈谈你的感受和体会。

       结对编程,在每一时刻都是一个程序员在编程,说效率如何高,也只是1+1>1,但是否大于2呢?答案是肯定的。首先,一个人的编程,平均很难实现1>80%×1的工作效力。但是在和同伴一起工作时,必须保持思维一直高度集中,所以平均都可以达到1>80%×1的个人效力,同时有了一遍代码评审,使得出错几率就降低,减少了bug的产生。也由于两个人的思想汇集,能创造了很多新编程算法或结构重用等。所以着眼于整个项目来看,这个实践确实大大提高了效率。本次结对编程,就很好的证明了1+1>2这一点。

posted on 2018-04-03 20:39  Fukang96  阅读(742)  评论(10编辑  收藏  举报

导航