软件工程---复利计算再升级

时间:2023-01-09 10:54:58

同伴姓名:卢琪
同伴学号:201402064105
博客地址:http://www.cnblogs.com/xiseven/

------------------------------------------------

目录:

1.更新内容

2.更新后的效果截图

3.核心代码及代码链接

4.总结

--------------------------------------------------------

1.更新内容

(1)改变了界面的颜色,使其视觉有更一步的体验

(2)整理了代码,使代码结构更加清晰合理

(3)添加了读取历史计算结果到显示面板的功能

-------------------------------------------------------

2.更新后的效果截图

 

软件工程---复利计算再升级

-------------------------------------------------------

3.核心代码及代码链接

读写文件的实现类

 1 public class DataFile {
 2     
 3     private static File f = new File("data.txt");
 4     
 5     public void writerData(String s) throws IOException {
 6         FileWriter fWriter = new FileWriter(f, true);//实现续写功能
 7         BufferedWriter bufw = new BufferedWriter(fWriter);
 8         bufw.write(s);
 9         bufw.newLine();
10         bufw.close();
11         fWriter.close();
12     }
13     
14     public LinkedList<String> getData() throws IOException {
15         f.createNewFile();
16         FileReader fReader = new FileReader(f);
17         BufferedReader bufr = new BufferedReader(fReader); 
18         LinkedList<String> linkedList = new LinkedList<String>();
19         String string = null;
20         while((string = bufr.readLine()) != null){
21             linkedList.add(string);
22         }
23         bufr.close();
24         fReader.close();
25         return linkedList;
26         
27     }
28 }

 对该类进行单元测试的代码:

 1 public class DataFileTest {
 2 
 3     
 4     
 5     String s1="sdafdas475854    4sad8sa4  as4d87sa4d ";
 6     String s2="456456c6v45yg6vg465vg45v6    4g65yt456 ";
 7     @Test
 8     public void testWriterData() throws IOException {
 9         DataFile dataflie=new DataFile();
10         dataflie.writerData(s1);
11         dataflie.writerData(s2);
12     }
13     
14     @Test
15     public void testGetData() throws IOException{
16         DataFile dataflie=new DataFile();
17         LinkedList<String> lls=dataflie.getData();
18         if (lls.size()!=0) {
19             
20         for (int i = 0; i < lls.size(); i++) {
21             System.out.println(lls.get(i));
22             if (i==0&&lls.get(i)!=null) {
23                 boolean flag = (s1.equals(lls.get(i)));
24                  assertEquals(true, flag);
25             } else if(i==1&&lls.get(i)!=null){
26                 boolean flag = (s2.equals(lls.get(i)));
27                  assertEquals(true, flag);
28             }
29         }
30         }
31         
32     }
33 }

 

 

主程序代码链接:

Compounding4_3.java:

https://github.com/helloyoucan/compoundung/blob/master/Compounding4_3.java

DataTreating1_1.java:

https://github.com/helloyoucan/compoundung/blob/master/DataTreating1_1.java

DataFile.java:

https://github.com/helloyoucan/compoundung/blob/master/DataFile.java

单元测试代码链接:

DataTreating1_1.java:

https://github.com/helloyoucan/compoundung/blob/master/DataTreating1_1.java

DataFileTest.java:

https://github.com/helloyoucan/compoundung/blob/master/DataFileTest.java

--------------------------------------------------------

4.总结

在该次改动中,同伴主要是提供一个读写文件的类,收到同伴的代码后,利用先前学到的单元测试经过不断的测试,发现了一小点问题,经过添加一条代码解决了。在这次合作做体验到了单元测试的实用性,说明了学习到东西总会有用到的地方的!