标签:
结对项目:复利计算
搭档:30蔡京航 http://www.cnblogs.com/cjh123/
github:https://github.com/alfredzhu/teamwork
工作照
一、项目需求:
即要追求利益,又要面对不可预知的金融投资风险, “不能把鸡蛋放在同一个篮子里”,所以有必要进行组合投资。
通过上述计算与对比,可以帮助客户进行投资决策。
客户:那么能否帮我记录下一笔一笔不同类型的投资,并动态显示资金现值呢?
二、完成要求:以结对方式完成。
在这次结对编程中分配任务 我:设计代码并审核,单元测试减少bug
蔡京航:设计界面,查阅资料,令代码规范并美观
在这这次结对编程的收获到和感悟:结对后,两个人都有不同的想法,在设计的时候可以及时提出质疑并觉得怎样做比较好
并指出错误,因此能互相受益,感觉很不错,能提高质量。
三、估算时间
估计用时:1.5h
估计代码行:300
实际用时:2.5h
实际代码行:304
四、用txt文件来动态显示历史信息
1 import java.io.BufferedWriter; 2 import java.io.File; 3 import java.io.FileNotFoundException; 4 import java.io.FileReader; 5 import java.io.FileWriter; 6 import java.io.IOException; 7 import java.io.Writer; 8 import java.util.ArrayList; 9 10 11 public class txtIO { 12 13 public static void main (String args[]) { 14 15 ReadDate(); 16 17 WriteDate(); 18 19 } 20 21 /** 22 * 读取数据 23 * @return 24 */ 25 public static void ReadDate() { 26 CompoundCalculator C=new CompoundCalculator(); 27 String url = "F:/gitfile/testgit/historydata.txt"; 28 try { 29 FileReader read = new FileReader(new File(url)); 30 StringBuffer sb = new StringBuffer(); 31 char ch[] = new char[1024]; 32 int d = read.read(ch); 33 while(d!=-1){ 34 String str = new String(ch,0,d); 35 sb.append(str); 36 d = read.read(ch); 37 } 38 C.jTextArea1.setText(sb.toString()); 39 System.out.print(sb.toString()); 40 } catch (FileNotFoundException e) { 41 e.printStackTrace(); 42 } catch (IOException e) { 43 e.printStackTrace(); 44 } 45 } 46 47 /** 48 * 写入数据 49 */ 50 public static void WriteDate() { 51 52 try{ 53 File file = new File("F:/gitfile/testgit/historydata.txt"); 54 Writer out = null ; 55 out = new FileWriter(file,true) ; 56 if (file.exists()) { 57 58 file.delete(); 59 } 60 CompoundCalculator C=new CompoundCalculator(); 61 double P=C.P, i=C.i, F=C.F;//F:复利终值 P:本金 i:利率 62 int N=C.N, M=C.M, m=C.m;//N:利率获取时间的整数倍 M:复利次数 m:月数 63 int result=C.result; 64 int action=C.action; 65 file.createNewFile(); 66 67 68 if(action==1){ 69 out.write("\r\n"+"复利"+"\r\n"); 70 out.write("本金:" + P + "\r\n" + "年利率(%):" + i + "\r\n" 71 + "存入年限:" + N + "\r\n" + "年复利次数:" + M + "\r\n" + "复利终值:" + F 72 + "\r\n"); 73 } 74 if(action==2){ 75 out.write("\r\n"+"单利"+"\r\n"); 76 out.write("本金:" + P + "\r\n" + "年利率(%):" + i + "\r\n" 77 + "存入年限:" + N + "\r\n" + "复利终值:" + F + "\r\n"); 78 } 79 if(action==3){ 80 out.write("\r\n"+"本金估算"+"\r\n"); 81 out.write("复利终值:" + F + "\r\n" + "年利率(%):" + i + "\r\n" 82 + "存入年限:" + N + "\r\n" + "年复利次数:" + M + "\r\n" + "本金:" + P 83 + "\r\n"); 84 } 85 if(action==4){ 86 out.write("\r\n"+"年限估算"+"\r\n"); 87 out.write("本金:" + P + "\r\n" + "年利率(%):" + i + "\r\n" 88 + "年复利次数:" + M + "\r\n" + "复利终值:" + F + "\r\n" + "年限:" + N 89 + "\r\n"); 90 } 91 if(action==5){ 92 out.write("\r\n"+"利率估算"+"\r\n"); 93 out.write("本金:" + P + "\r\n" + "存入年限:" + N + "\r\n" + "年复利次数:" 94 + M + "\r\n" + "复利终值:" + F + "\r\n" + "年利率(%):" + i + "\r\n"); 95 } 96 if(action==6){ 97 out.write("\r\n"+"定期投资(年)"+"\r\n"); 98 out.write("年投资金额:" + P + "\r\n" + "年利率(%):" + i + "\r\n" 99 + "定投年数:" + N + "\r\n" + "终值:" + F + "\r\n"); 100 } 101 if(action==7){ 102 out.write("\r\n"+"定期投资(月)"+"\n"); 103 out.write("月投资金额:" + P + "\r\n" + "年利率(%):" + i + "\r\n" 104 + "定投月数:" + m + "\r\n" + "终值:" + F + "\r\n"); 105 } 106 if(action==8){ 107 out.write("\r\n"+"等额本息还款"+"\r\n"); 108 out.write("贷款金额:" + P + "\r\n" + "年利率(%):" + i + "\r\n" 109 + "年限:" + N + "\r\n" + "年复利次数:" + M + "\r\n" + "等额本息还款额:" + F 110 + "\r\n"); 111 } 112 //} 113 out.close(); 114 } catch (Exception ex) { 115 System.out.println(ex); 116 } 117 118 } 119 120 }
五、运行效果
标签:
原文地址:http://www.cnblogs.com/alfredzhu/p/5357410.html