参考:
关于实现两级联动下拉框 参考:
javaSwing_2.9: JComboBox (下拉列表框)
JAVA SWING 下拉列表框中的值如何获取:
JComboBox jComboBox;
String value = jComboBox.getSelectedItem().toString();
UI.java
这里代码主要是针对UI界面的实现
package UI; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.IOException; import javax.swing.JComboBox; import FundProfit.*; public class UI { /* 测试UI public static void main(String[] args){ UI u = new UI(); u.initUI(); } */ private String[] month={"01","02","03","04","05","06","07","08","09","10","11","12"}; private String[] day={"31","29","31","30","31","30","31","31","30","28","30","31"}; private String[] hour={"1","2"}; public void initUI(){ javax.swing.JFrame frame = new javax.swing.JFrame();//实例化一个窗体对象 frame.setTitle("汇添富移动互联股票(000697)基金收益程序");//设置窗体的标题 frame.setSize(600,600); //设置窗体的大小 frame.setLocationRelativeTo(null); //设置窗体的位置为居中 frame.setResizable(false); //设置不可调节大小 frame.setDefaultCloseOperation(3); //设置窗体的关闭操作。这个方法有0 1 2 3四个返回值。 //其中0是指不关闭,也就是说无论点击多少次按钮都不会有反应 //1是指点击关闭按钮会关闭这个窗体,但是程序依然在后台运行。 //2是指如果有多个窗体就关闭当前窗体,如果只有一个则关闭程序。 //3是指直接关闭程序。 frame.setBackground(Color.LIGHT_GRAY);//设置窗体的背景颜色。 /*如果不加如下代码会出现一个巨大的登录按钮 * Jframe窗体的默认布局是边框布局,也就是说我们前面要加的东西确实已经加上了,但是被一层一层覆盖掉了。 * 所以这个时候我们就需要设置一个窗体的布局。我们可以把窗体设置成流式布局(FlowLayout) * * java.awt.Flowayout 流式布局类似word文档(所有的布局类都只能应用于容器组建上) * * 这段代码要在设置背景颜色之后 * */ //java.awt.FlowLayout fl = new java.awt.FlowLayout(); //frame.setLayout(fl); javax.swing.JPanel northPanel = new javax.swing.JPanel(); northPanel.setPreferredSize(new java.awt.Dimension(0,100)); frame.add(northPanel,java.awt.BorderLayout.NORTH); javax.swing.JPanel centerPanel = new javax.swing.JPanel(); //中部面板设置 javax.swing.JLabel Lname_1 = new javax.swing.JLabel("投资基金金额: "); //实例化一个标签 Lname_1.setFont(new Font("楷体",Font.BOLD,20)); centerPanel.add(Lname_1); //加在面板上!!!! javax.swing.JTextField Tname = new javax.swing.JTextField();//实例化一个文本输入框对象并调整大小 java.awt.Dimension dim = new java.awt.Dimension(250,30); Tname.setPreferredSize(dim); centerPanel.add(Tname); //加在面板上!!!! javax.swing.JLabel Lname_2 = new javax.swing.JLabel("申 购 时 间: "); //实例化一个标签对象并调整字体、大小 Lname_2.setFont(new Font("楷体",Font.BOLD,20)); centerPanel.add(Lname_2); //加在面板上!!!! /* javax.swing.JTextField Tname_2 = new javax.swing.JTextField(); java.awt.Dimension dim_2 = new java.awt.Dimension(250,30); Tname_2.setPreferredSize(dim_2); centerPanel.add(Tname_2); //加在面板上!!!! */ /************************/ final javax.swing.JComboBox<String> comboBox_1 = new javax.swing.JComboBox<String>(month);//创建一个下拉链表框 comboBox_1.setSelectedIndex(-1); //设置默认选中的项目 centerPanel.add(comboBox_1); //加在面板上!!!! final javax.swing.JComboBox<String> comboBox_2 = new javax.swing.JComboBox<String>(); centerPanel.add(comboBox_2); javax.swing.JLabel Lname_4 = new javax.swing.JLabel("第"); Lname_4.setFont(new Font("楷体",Font.BOLD,15)); centerPanel.add(Lname_4); final javax.swing.JComboBox<String> comboBox_5 = new javax.swing.JComboBox<String>(hour); comboBox_5.setSelectedIndex(-1); centerPanel.add(comboBox_5); javax.swing.JLabel Lname_5 = new javax.swing.JLabel("时间段"); Lname_5.setFont(new Font("楷体",Font.BOLD,15)); centerPanel.add(Lname_5); comboBox_1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { comboBox_2.removeAllItems(); //清空comboBox_2中的内容 int i = Integer.parseInt(comboBox_1.getSelectedItem().toString())-1; //获取月份 int count = Integer.parseInt(day[i]); //根据月份获取相应天数 String[] Day = new String[count]; // 添加天数 if(i==0){ for( int j=3; j<count; j++){ String t; if(j<9){ t="0"; t = t+String.valueOf(j+1); } else{ t = String.valueOf(j+1); } comboBox_2.addItem(t); } } else if(i==10){ for( int j=0; j<count; j++){ String t; if(j<9){ t="0"; t = t+String.valueOf(j+1); } else{ t = String.valueOf(j+1); } comboBox_2.addItem(t); } } else { for (int j = 0; j < count; j++) { String t; if (j < 9) { t = "0"; t = t + String.valueOf(j + 1); } else { t = String.valueOf(j + 1); } comboBox_2.addItem(t); } } } }); /************************/ javax.swing.JLabel Lname_3 = new javax.swing.JLabel("赎 回 时 间: "); Lname_3.setFont(new Font("楷体",Font.BOLD,20)); centerPanel.add(Lname_3); //加在面板上!!!! /* javax.swing.JTextField Tname_3 = new javax.swing.JTextField(); java.awt.Dimension dim_3 = new java.awt.Dimension(250,30); Tname_3.setPreferredSize(dim_3); centerPanel.add(Tname_3); //加在面板上!!!! */ /************************/ final javax.swing.JComboBox<String> comboBox_3 = new javax.swing.JComboBox<String>(month);//创建一个下拉链表框 comboBox_3.setSelectedIndex(-1); //设置默认选中的项目 centerPanel.add(comboBox_3); //加在面板上!!!! final javax.swing.JComboBox<String> comboBox_4 = new javax.swing.JComboBox<String>(); centerPanel.add(comboBox_4); javax.swing.JLabel Lname_6 = new javax.swing.JLabel("第"); Lname_6.setFont(new Font("楷体",Font.BOLD,15)); centerPanel.add(Lname_6); final javax.swing.JComboBox<String> comboBox_6 = new javax.swing.JComboBox<String>(hour); comboBox_6.setSelectedIndex(-1); centerPanel.add(comboBox_6); javax.swing.JLabel Lname_7 = new javax.swing.JLabel("时间段"); Lname_7.setFont(new Font("楷体",Font.BOLD,15)); centerPanel.add(Lname_7); comboBox_3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { comboBox_4.removeAllItems(); int i_2 = Integer.parseInt(comboBox_3.getSelectedItem().toString())-1; int count = Integer.parseInt(day[i_2]); String[] Day = new String[count]; if(i_2==0){ for( int j_2=3; j_2<count; j_2++){ String t; if(j_2<9){ t="0"; t = t+String.valueOf(j_2+1); } else{ t = String.valueOf(j_2+1); } comboBox_4.addItem(t); } } else if(i_2==10){ for( int j_2=0; j_2<count; j_2++){ String t; if(j_2<9){ t="0"; t = t+String.valueOf(j_2+1); } else{ t = String.valueOf(j_2+1); } comboBox_4.addItem(t); } } else { for (int j_2 = 0; j_2 < count; j_2++) { String t; if (j_2 < 9) { t = "0"; t = t + String.valueOf(j_2 + 1); } else { t = String.valueOf(j_2 + 1); } comboBox_4.addItem(t); } } } }); /************************/ /* javax.swing.JLabel Lname_4 = new javax.swing.JLabel("输入时间区间范围:2016-01-04~2016-10-28"); Lname_4.setFont(new Font("楷体",Font.PLAIN,15)); javax.swing.JLabel Lname_5 = new javax.swing.JLabel("格式为:2016-01-04 23:59:59"); Lname_5.setFont(new Font("楷体",Font.PLAIN,15)); centerPanel.add(Lname_4); //加在面板上!!!! centerPanel.add(Lname_5); //加在面板上!!!! */ javax.swing.JLabel Lname_8 = new javax.swing.JLabel(" 第1时间段为9:00~15:00"); Lname_8.setFont(new Font("楷体",Font.PLAIN,15)); centerPanel.add(Lname_8); javax.swing.JButton Bcomfirm = new javax.swing.JButton("确认"); //实例化一个按钮对象并调整字体、大小 Bcomfirm.setPreferredSize(new java.awt.Dimension(200,40)); Bcomfirm.setFont(new Font("楷体",Font.BOLD,20)); centerPanel.add(Bcomfirm); //加在面板上!!!! frame.add(centerPanel,java.awt.BorderLayout.CENTER); //中部面板设置完成 javax.swing.JPanel westPanel = new javax.swing.JPanel(); //设置左边的面板 westPanel.setPreferredSize(new java.awt.Dimension(80,0)); westPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));//流式布局设置为靠右对齐 frame.add(westPanel,java.awt.BorderLayout.WEST); //设置完成 javax.swing.JPanel eastPanel = new javax.swing.JPanel(); eastPanel.setPreferredSize(new java.awt.Dimension(80,0)); frame.add(eastPanel,java.awt.BorderLayout.EAST); //右边的面板 /* EventListener bu = new EventListener(); Bcomfirm.addActionListener(bu); bu.setDi(Tname); bu.setJpt(Tname_2); bu.setJrt(Tname_3); */ Bcomfirm.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double di; //投资基金金额 String jpt; //申购时间 String jrt; //赎回时间 String s =Tname.getText(); di = Double.parseDouble("".equals(s)?"0.00":s); jpt = comboBox_1.getSelectedItem().toString()+comboBox_5.getSelectedItem() +comboBox_2.getSelectedItem().toString(); //1 jrt = comboBox_3.getSelectedItem().toString()+comboBox_6.getSelectedItem().toString() +comboBox_4.getSelectedItem().toString();//2 FundProfit f = new FundProfit(); try { f.readTxt(); } catch (IOException e1) { e1.printStackTrace(); } //System.out.println("di:" + di); f.setInvestmentAmount(di); f.setPurchaseTime(jpt);//1 f.setRedeemTime(jrt); //2 double num; //基金份额数 double redemption; //赎回金额 double income; //基金收益 num = f.NumberOfFundShares(); redemption = f.RedemptionAmount(num); income = redemption - di; if(f.InputError()) { double net_1 = f.getPurNet(); double net_2 = f.getRedNet(); int day_1 = f.getDay_1(); initA(num, redemption, income, net_1, net_2, di, day_1); } else { initB(); } } }); frame.setVisible(true); //设置窗体可见。如果不设置这一步那么窗体看不见。另外所有的组建都要加在这个方法之间,否则不可见。 } public void initA(double n, double r, double i, double net_1, double net_2, double di, int day_1){//输出数据 javax.swing.JFrame frame = new javax.swing.JFrame(); frame.setTitle("结果"); frame.setSize(450,450); frame.setDefaultCloseOperation(2); frame.setLocationRelativeTo(null); javax.swing.JPanel centerPanel = new javax.swing.JPanel(); javax.swing.JLabel Lname_1 = new javax.swing.JLabel(" 基金份额数:"); Lname_1.setFont(new Font("楷体",Font.BOLD,25)); centerPanel.add(Lname_1); javax.swing.JLabel Lresult_1 = new javax.swing.JLabel(" "+String.format("%.2f",n)); Lresult_1.setFont(new Font("楷体",Font.PLAIN,20)); centerPanel.add(Lresult_1); javax.swing.JLabel Lname_2 = new javax.swing.JLabel(" 赎 回 金 额: "); Lname_2.setFont(new Font("楷体",Font.BOLD,25)); centerPanel.add(Lname_2); javax.swing.JLabel Lresult_2 = new javax.swing.JLabel(String.format("%.2f",r)); Lresult_2.setFont(new Font("楷体", Font.PLAIN,20)); centerPanel.add(Lresult_2); javax.swing.JLabel Lname_3 = new javax.swing.JLabel("基 金 收 益: "); Lname_3.setFont(new Font("楷体",Font.BOLD,25)); centerPanel.add(Lname_3); javax.swing.JLabel Lresult_3 = new javax.swing.JLabel(String.format("%.2f",i)); Lresult_3.setFont(new Font("楷体", Font.PLAIN,20)); centerPanel.add(Lresult_3); javax.swing.JButton Details = new javax.swing.JButton("详情"); //实例化一个按钮对象并调整字体、大小 Details.setPreferredSize(new java.awt.Dimension(200,40)); Details.setFont(new Font("楷体",Font.BOLD,20)); centerPanel.add(Details); frame.add(centerPanel, java.awt.BorderLayout.CENTER); javax.swing.JPanel northPanel = new javax.swing.JPanel(); //设置上边的面板 northPanel.setPreferredSize(new java.awt.Dimension(0,50)); frame.add(northPanel, BorderLayout.NORTH); javax.swing.JPanel westPanel = new javax.swing.JPanel(); //设置左边的面板 westPanel.setPreferredSize(new java.awt.Dimension(75,0)); westPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));//流式布局设置为靠右对齐 frame.add(westPanel,java.awt.BorderLayout.WEST); //设置完成 javax.swing.JPanel eastPanel = new javax.swing.JPanel(); eastPanel.setPreferredSize(new java.awt.Dimension(75,0)); frame.add(eastPanel,java.awt.BorderLayout.EAST); //右边的面板 Details.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { javax.swing.JFrame frame = new javax.swing.JFrame(); frame.setTitle("详情"); frame.setSize(700,600); frame.setDefaultCloseOperation(2); frame.setLocationRelativeTo(null); javax.swing.JPanel centerPanel = new javax.swing.JPanel(); javax.swing.JLabel Lname_1 = new javax.swing.JLabel("基金份额数=购买金额/(1+申购费率)/当天净值"); Lname_1.setFont(new Font("楷体",Font.BOLD,21)); centerPanel.add(Lname_1); javax.swing.JLabel Lname_2 = new javax.swing.JLabel("当天净值:"+net_1); Lname_2.setFont(new Font("楷体",Font.PLAIN,18)); centerPanel.add(Lname_2); javax.swing.JLabel Lname_3 = new javax.swing.JLabel(); if( di<1000000 ){ Lname_3.setText("因为购买金额小于100万所以 申购率:0.15%"); } else if( di<5000000){ Lname_3.setText("因为购买金额大于等于100万,小于500万所以 申购率:0.10%"); } else if( di<10000000){ Lname_3.setText("因为购买金额大于等于500万,小于1000万所以 申购率:0.03%"); } else{ Lname_3.setText("因为购买金额大于等于1000万 申购率:1000元/笔"); } Lname_3.setFont(new Font("楷体",Font.PLAIN,18)); centerPanel.add(Lname_3); javax.swing.JLabel Lname_4 = new javax.swing.JLabel("赎回金额=赎回份额数*当天净值*(1-赎回费率)"); Lname_4.setFont(new Font("楷体",Font.BOLD,21)); centerPanel.add(Lname_4); javax.swing.JLabel Lname_5 = new javax.swing.JLabel("当天净值:"+net_2); Lname_5.setFont(new Font("楷体",Font.PLAIN,18)); centerPanel.add(Lname_5); javax.swing.JLabel Lname_6 = new javax.swing.JLabel(); if( day_1<7 ){ Lname_6.setText("因为持有期限小于7天 赎回费率:1.5%"); } else if( di<5000000){ Lname_6.setText("因为持有期限大于等于7天,小于30天 赎回费率:0.75%"); } else if( di<10000000){ Lname_6.setText("因为持有期限大于等于30天,小于180天 赎回费率:0.50%"); } else{ Lname_6.setText("因为持有期限大于等于180天 赎回费率:0.00%"); } Lname_6.setFont(new Font("楷体",Font.PLAIN,18)); centerPanel.add(Lname_6); frame.add(centerPanel, java.awt.BorderLayout.CENTER); javax.swing.JPanel northPanel = new javax.swing.JPanel(); //设置上边的面板 northPanel.setPreferredSize(new java.awt.Dimension(0,50)); frame.add(northPanel, BorderLayout.NORTH); javax.swing.JPanel westPanel = new javax.swing.JPanel(); //设置左边的面板 westPanel.setPreferredSize(new java.awt.Dimension(75,0)); westPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));//流式布局设置为靠右对齐 frame.add(westPanel,java.awt.BorderLayout.WEST); //设置完成 javax.swing.JPanel eastPanel = new javax.swing.JPanel(); eastPanel.setPreferredSize(new java.awt.Dimension(75,0)); frame.add(eastPanel,java.awt.BorderLayout.EAST); //右边的面板 frame.setVisible(true); } }); frame.setVisible(true); } public void initB(){ javax.swing.JFrame frame = new javax.swing.JFrame(); frame.setTitle("结果"); frame.setSize(350,200); frame.setDefaultCloseOperation(2); frame.setLocationRelativeTo(null); javax.swing.JPanel centerPanel = new javax.swing.JPanel(); javax.swing.JLabel Lname_1 = new javax.swing.JLabel("输入时间错误!"); Lname_1.setFont(new Font("楷体",Font.BOLD,25)); centerPanel.add(Lname_1); frame.add(centerPanel, java.awt.BorderLayout.CENTER); javax.swing.JPanel northPanel = new javax.swing.JPanel(); //设置上边的面板 northPanel.setPreferredSize(new java.awt.Dimension(0,50)); frame.add(northPanel, BorderLayout.NORTH); javax.swing.JPanel westPanel = new javax.swing.JPanel(); //设置左边的面板 westPanel.setPreferredSize(new java.awt.Dimension(75,0)); westPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));//流式布局设置为靠右对齐 frame.add(westPanel,java.awt.BorderLayout.WEST); //设置完成 javax.swing.JPanel eastPanel = new javax.swing.JPanel(); eastPanel.setPreferredSize(new java.awt.Dimension(75,0)); frame.add(eastPanel,java.awt.BorderLayout.EAST); //右边的面板 frame.setVisible(true); } }
FundProfit.java
这里的代码主要实现 互联股票的算法
package FundProfit; import java.util.*; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class FundProfit { TreeMap NetWorth = new TreeMap(); double InvestmentAmount; String PurchaseTime; String RedeemTime; double net_1; double net_2; int day_1; public double getPurNet(){ return net_1; } public double getRedNet(){ return net_2; } //int flag=0; public int getDay_1(){ return day_1; } public boolean InputError(){ if( Integer.parseInt(PurchaseTime.substring(0,2)) > Integer.parseInt(RedeemTime.substring(0,2)) ){ return false; } else if( Integer.parseInt(PurchaseTime.substring(0,2)) == Integer.parseInt(RedeemTime.substring(0,2)) ){ if( Integer.parseInt(PurchaseTime.substring(3)) > Integer.parseInt(RedeemTime.substring(3)) ){ return false; } else{ return true; } } else{ return true; } /* if(flag!=0) return false; else return true; */ } public void setInvestmentAmount(double d){ //设置获取投资基金的方法 InvestmentAmount = d; } public void setPurchaseTime(String s){ //设置获取投资时间的方法 PurchaseTime = s; } public void setRedeemTime(String s){ //设置赎回时间的方法 RedeemTime = s; } /* 从data.txt中读取数据 */ public void readTxt() throws IOException{ FileReader fr = new FileReader("data.txt"); BufferedReader br = new BufferedReader(fr); String line; while( (line=br.readLine())!=null){ String m=line.substring(5,10); NetWorth.put(m,line.substring(11,16)); //构造TreeMap取 0~9位为日期定为key 11~15为净值定位value } } /* 通过日期得到净值 */ public double getNetWorth(String Time){ Iterator iter = NetWorth.keySet().iterator(); // keySet() 集合试图 然后利用迭代器遍历TreeMap String str1 = Time.substring(0,2)+"-"+Time.substring(3);//年月日 String str2 = Time.substring(2,3); // hour double net=0; //净值 int hour; hour = Integer.valueOf(str2).intValue(); //String->int /* 不断遍历TreeMap得到相应日期的净值跳出 */ Object key; while(iter.hasNext()){ key = iter.next(); if(key.toString().compareTo(str1) == 0){ //如果日期相同 if( hour==1 ){ //判断是不是在工作日的工作时段中 key = iter.next(); net = Double.parseDouble(NetWorth.get(key).toString()); // object->String->int } else{ net = Double.parseDouble(NetWorth.get(key).toString()); // object->String->int } break; } else if(key.toString().compareTo(str1) > 0){ //如果不在工作日,则算到下一个工作日的净值 net = Double.parseDouble(NetWorth.get(key).toString()); // object->String->int } } /********** 如果找到相应的日期则输出 输入日期错误,但这里有做到用户交互界面这是接下来我要做的 **********/ /* if(net==0){ flag = 1; } */ return net; } /* 申购日期和赎回日期相差几天 */ public int getDay(){ int day=0; int p_month = Integer.parseInt(PurchaseTime.substring(0,2)); //申购日期月份 int p_day = Integer.parseInt(PurchaseTime.substring(3)); //申购日期的day int r_month = Integer.parseInt(RedeemTime.substring(0,2)); //赎回日期的月份 int r_day = Integer.parseInt(RedeemTime.substring(3)); //赎回日期的day /* 如果月份不相同,则先算申购时间到下一个月的天数。然后如此遍历,直到到赎回约分为止。如果是同约分则直接相减 */ if(p_month!=r_month) { switch (p_month) { case 1: case 3: case 5: case 7: case 8: case 10: day = 31 - p_day + 1; break; case 4: case 6: case 9: day = 30 - p_day + 1; break; case 2: day = 29 - p_day + 1; break; } for (int i = p_month+1; i < r_month; i++) { switch (i){ case 2: day+=29; break; case 3: case 5: case 7: case 8: day+=31; break; case 4: case 6: case 9: day+=30; break; } } day+=r_day; } else{ day = r_day - p_day+1; } day_1 = day; return day; } /* 计算基金份额数 */ public double NumberOfFundShares(){ double net = getNetWorth(PurchaseTime); net_1 = net; double num; if(InvestmentAmount < 1000000) num = InvestmentAmount/(1+0.0015)/net; else if(InvestmentAmount < 5000000) num = InvestmentAmount/(1+0.001)/net; else if(InvestmentAmount < 10000000) num = InvestmentAmount/(1+0.0003)/net; else num = (InvestmentAmount-1000)/net; return num; } /* 计算赎回金额 */ public double RedemptionAmount(double num){ double net = getNetWorth(RedeemTime); net_2 = net; int day = getDay(); double amount=0; if(day<7) amount = num*net*(1-0.0015); else if(day<30) amount = num*net*(1-0.0075); else if(day<180) amount = num*net*(1-0.005); else amount = num*net; return amount; } }
Test.java
package Test; import UI.*; public class Test { public static void main(String[] args){ UI u = new UI(); u.initUI(); } }
关于基础界面
当输入时间正常(即赎回时间大于申购时间
点击确定
点击 详情
当输入时间错误(即赎回时间小于申购时间
点击 确定
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
购买基金是人们常用的投资理财方式之一,投资者可以通过基金公司、天天基金网、蚂蚁聚宝、合作银行等渠道购买基金,实现金融资产的稳健增值。 汇添富移动互联股票型证券投资基金(简称汇添富移动互联股票,基金代码为000697)是汇添富基金管理股份有限公司的一个股票型的基金理财产品。该基金基金的投资范围为具有良好流动性的金融工具,包括国内依法发行上市的股票(含中小板、创业板及其他经中国证监会核准上市的股票)、债券、货币市场工具、股指期货、权证、资产支持证券、银行存款以及法律法规或中国证监会允许基金投资的其他金融工具。 通过网络在线购买该基金的前端申购费率如下: 序号 购买金额X 申购费率 1 X<100万 0.15% 2 100万<=X<500万 0.10% 3 500万<=X<1000万 0.03% 4 X>=1000万 1000元/笔 通过网络在线赎回该基金的赎回购费率如下: 序号 持有期限D 赎回费率 1 D<7天 1.5% 2 7天<=D<30天 0.75% 3 30天<=D<180天 0.50% 4 D>=180天 0.00% 申购基金的原则:投资者在开放期(每个工作日的9:00~15:00)购买基金的,则以该基金当天的净值计算申购的份额数(份额数=购买金额/(1+申购费率)/当天净值),否则以下一个工作日的净值来计算申购的份额数。比如汇添富移动互联股票(000697)在2016年10月26日的净值1.606,而2016年10月27日的净值是1.602,如果投资者在2016年10月26日在9:00~15:00时间段申购了10000元,则他申购该基金的确认份额数为10000/(1+0.15%)/1.606=6217.32份;若在2016年10月26日15点至2016年10月27日9点期间申购的,则申购该基金的确认份额数为10000/(1+0.15%)/1.602=6232.85份;以此类推。 赎回基金的原则:投资者在开放时间(每个工作日的9:00~15:00)赎回基金的,则以该基金当天的净值计算赎回金额,其中赎回金额=赎回份额数*当天净值*(1-赎回费率),0<赎回份额数<=拥有的份额数,否则以下一个工作日的净值来计算赎回金额。比如汇添富移动互联股票(000697)在2016年10月26日的净值1.606,而2016年10月27日的净值是1.602,如果投资者(假设他/她持有该基金的时间为23天)在2016年10月26日在9:00~15:00时间段赎回10000份,则赎回该基金的确认金额10000*(1-0.75%)*1.606=15939.55元;若在2016年10月26日15点至2016年10月27日9点期间赎回的,则赎回该基金的确认金额10000*(1-0.75%)*1.602=15899.85元;以此类推。 投资基金收益=赎回基金确认金额-申购基金金额。 请您以汇添富移动互联股票(000697)2016年以来的历史净值情况为例(见附件),编写一个基金收益程序。要求输入任意的投资基金金额、申购时间和赎回时间,输出基金份额数、赎回金额和基金收益。要求申购时间比赎回时间早,申购时间和赎回时间在2016年1月1日至2016年10月31日之间。要求申购或赎回时间格式为“年-月-日 时:分:秒”,如:2016-10-30 21:32:15 提示:可将汇添富移动互联股票(000697)今年以来的历史净值以二维数组或TreeMap初始化(日期和净值即可)或通过txt文件读取。 附件 汇添富移动互联股票(000697)历史净值 (来源:http://finance.sina.com.cn/fund/quotes/000697/bc.shtml) 日期 单位净值(元) 累计净值(元) 净值增长率 2016-10-28 1.596 1.596 -0.375% 2016-10-27 1.602 1.602 -0.249% 2016-10-26 1.606 1.606 -0.864% 2016-10-25 1.620 1.620 0.310% 2016-10-24 1.615 1.615 0.937% 2016-10-21 1.600 1.600 -0.559% 2016-10-20 1.609 1.609 0.815% 2016-10-19 1.596 1.596 -0.063% 2016-10-18 1.597 1.597 1.397% 2016-10-17 1.575 1.575 -1.068% 2016-10-14 1.592 1.592 -0.188% 2016-10-13 1.595 1.595 0% 2016-10-12 1.595 1.595 -0.188% 2016-10-11 1.598 1.598 0% 2016-10-10 1.598 1.598 2.699% 2016-09-30 1.556 1.556 0.712% 2016-09-29 1.545 1.545 0.260% 2016-09-28 1.541 1.541 -0.259% 2016-09-27 1.545 1.545 0.849% 2016-09-26 1.532 1.532 -1.983% 2016-09-23 1.563 1.563 -0.319% 2016-09-22 1.568 1.568 0.320% 2016-09-21 1.563 1.563 0.128% 2016-09-20 1.561 1.561 -0.256% 2016-09-19 1.565 1.565 1.294% 2016-09-14 1.545 1.545 -0.194% 2016-09-13 1.548 1.548 0.324% 2016-09-12 1.543 1.543 -3.199% 2016-09-09 1.594 1.594 -1.300% 2016-09-08 1.615 1.615 0.498% 2016-09-07 1.607 1.607 -0.310% 2016-09-06 1.612 1.612 1.832% 2016-09-05 1.583 1.583 0.253% 2016-09-02 1.579 1.579 -0.316% 2016-09-01 1.584 1.584 -0.440% 2016-08-31 1.591 1.591 -0.500% 2016-08-30 1.599 1.599 0% 2016-08-29 1.599 1.599 0.125% 2016-08-26 1.597 1.597 0.188% 2016-08-25 1.594 1.594 -0.561% 2016-08-24 1.603 1.603 0.945% 2016-08-23 1.588 1.588 0.189% 2016-08-22 1.585 1.585 -1.614% 2016-08-19 1.611 1.611 0.187% 2016-08-18 1.608 1.608 -0.372% 2016-08-17 1.614 1.614 0.498% 2016-08-16 1.606 1.606 0% 2016-08-15 1.606 1.606 3.147% 2016-08-12 1.557 1.557 0.777% 2016-08-11 1.545 1.545 -1.967% 2016-08-10 1.576 1.576 -0.442% 2016-08-09 1.583 1.583 0.828% 2016-08-08 1.570 1.570 1.095% 2016-08-05 1.553 1.553 -1.209% 2016-08-04 1.572 1.572 1.223% 2016-08-03 1.553 1.553 0% 2016-08-02 1.553 1.553 0.975% 2016-08-01 1.538 1.538 -0.966% 2016-07-29 1.553 1.553 -1.146% 2016-07-28 1.571 1.571 -1.443% 2016-07-27 1.594 1.594 -5.680% 2016-07-26 1.690 1.690 1.137% 2016-07-25 1.671 1.671 -0.476% 2016-07-22 1.679 1.679 -1.002% 2016-07-21 1.696 1.696 -0.059% 2016-07-20 1.697 1.697 0.059% 2016-07-19 1.696 1.696 0.713% 2016-07-18 1.684 1.684 -0.237% 2016-07-15 1.688 1.688 -1.055% 2016-07-14 1.706 1.706 0.059% 2016-07-13 1.705 1.705 1.067% 2016-07-12 1.687 1.687 0.897% 2016-07-11 1.672 1.672 -0.358% 2016-07-08 1.678 1.678 0.239% 2016-07-07 1.674 1.674 -0.594% 2016-07-06 1.684 1.684 0.238% 2016-07-05 1.680 1.680 0.119% 2016-07-04 1.678 1.678 1.574% 2016-07-01 1.652 1.652 -0.840% 2016-06-30 1.666 1.666 0.361% 2016-06-29 1.660 1.660 -0.180% 2016-06-28 1.663 1.663 0.666% 2016-06-27 1.652 1.652 2.672% 2016-06-24 1.609 1.609 -0.740% 2016-06-23 1.621 1.621 0.247% 2016-06-22 1.617 1.617 2.536% 2016-06-21 1.577 1.577 -0.942% 2016-06-20 1.592 1.592 0.569% 2016-06-17 1.583 1.583 0.444% 2016-06-16 1.576 1.576 -0.505% 2016-06-15 1.584 1.584 3.462% 2016-06-14 1.531 1.531 -0.584% 2016-06-13 1.540 1.540 -5.810% 2016-06-08 1.635 1.635 -0.487% 2016-06-07 1.643 1.643 -0.061% 2016-06-06 1.644 1.644 0.305% 2016-06-03 1.639 1.639 0.862% 2016-06-02 1.625 1.625 1.057% 2016-06-01 1.608 1.608 0.878% 2016-05-31 1.594 1.594 5.354% 2016-05-30 1.513 1.513 -0.198% 2016-05-27 1.516 1.516 -0.720% 2016-05-26 1.527 1.527 0.792% 2016-05-25 1.515 1.515 -0.329% 2016-05-24 1.520 1.520 -0.848% 2016-05-23 1.533 1.533 1.322% 2016-05-20 1.513 1.513 1.340% 2016-05-19 1.493 1.493 0.674% 2016-05-18 1.483 1.483 -2.818% 2016-05-17 1.526 1.526 1.127% 2016-05-16 1.509 1.509 1.616% 2016-05-13 1.485 1.485 -0.802% 2016-05-12 1.497 1.497 0.335% 2016-05-11 1.492 1.492 -1.971% 2016-05-10 1.522 1.522 -0.588% 2016-05-09 1.531 1.531 -3.650% 2016-05-06 1.589 1.589 -4.162% 2016-05-05 1.658 1.658 0.974% 2016-05-04 1.642 1.642 0.061% 2016-05-03 1.641 1.641 3.598% 2016-04-29 1.584 1.584 -0.189% 2016-04-28 1.587 1.587 0% 2016-04-27 1.587 1.587 -0.251% 2016-04-26 1.591 1.591 1.016% 2016-04-25 1.575 1.575 -0.881% 2016-04-22 1.589 1.589 1.404% 2016-04-21 1.567 1.567 -1.632% 2016-04-20 1.593 1.593 -5.066% 2016-04-19 1.678 1.678 0.299% 2016-04-18 1.673 1.673 -1.819% 2016-04-15 1.704 1.704 -0.409% 2016-04-14 1.711 1.711 0.944% 2016-04-13 1.695 1.695 1.497% 2016-04-12 1.670 1.670 -0.713% 2016-04-11 1.682 1.682 1.631% 2016-04-08 1.655 1.655 -0.958% 2016-04-07 1.671 1.671 -1.416% 2016-04-06 1.695 1.695 -0.118% 2016-04-05 1.697 1.697 3.287% 2016-04-01 1.643 1.643 -0.725% 2016-03-31 1.655 1.655 -0.241% 2016-03-30 1.659 1.659 4.669% 2016-03-29 1.585 1.585 -1.858% 2016-03-28 1.615 1.615 -0.859% 2016-03-25 1.629 1.629 -0.489% 2016-03-24 1.637 1.637 -2.269% 2016-03-23 1.675 1.675 2.761% 2016-03-22 1.630 1.630 -0.488% 2016-03-21 1.638 1.638 2.825% 2016-03-18 1.593 1.593 5.079% 2016-03-17 1.516 1.516 4.913% 2016-03-16 1.445 1.445 -1.027% 2016-03-15 1.460 1.460 -0.748% 2016-03-14 1.471 1.471 5.222% 2016-03-11 1.398 1.398 -0.356% 2016-03-10 1.403 1.403 -2.162% 2016-03-09 1.434 1.434 -2.515% 2016-03-08 1.471 1.471 1.239% 2016-03-07 1.453 1.453 2.541% 2016-03-04 1.417 1.417 -4.963% 2016-03-03 1.491 1.491 0.134% 2016-03-02 1.489 1.489 4.272% 2016-03-01 1.428 1.428 1.854% 2016-02-29 1.402 1.402 -6.032% 2016-02-26 1.492 1.492 -1.257% 2016-02-25 1.511 1.511 -7.357% 2016-02-24 1.631 1.631 -1.865% 2016-02-23 1.662 1.662 0% 2016-02-22 1.662 1.662 2.403% 2016-02-19 1.623 1.623 0.682% 2016-02-18 1.612 1.612 -1.044% 2016-02-17 1.629 1.629 2.647% 2016-02-16 1.587 1.587 5.449% 2016-02-15 1.505 1.505 1.142% 2016-02-05 1.488 1.488 -2.490% 2016-02-04 1.526 1.526 2.210% 2016-02-03 1.493 1.493 0.606% 2016-02-02 1.484 1.484 5.323% 2016-02-01 1.409 1.409 -1.675% 2016-01-29 1.433 1.433 4.142% 2016-01-28 1.376 1.376 -6.267% 2016-01-27 1.468 1.468 -0.542% 2016-01-26 1.476 1.476 -7.286% 2016-01-25 1.592 1.592 1.144% 2016-01-22 1.574 1.574 1.877% 2016-01-21 1.545 1.545 -5.273% 2016-01-20 1.631 1.631 -1.271% 2016-01-19 1.652 1.652 4.030% 2016-01-18 1.588 1.588 3.520% 2016-01-15 1.534 1.534 -3.034% 2016-01-14 1.582 1.582 5.396% 2016-01-13 1.501 1.501 -4.880% 2016-01-12 1.578 1.578 -0.316% 2016-01-11 1.583 1.583 -7.535% 2016-01-08 1.712 1.712 0.058% 2016-01-07 1.711 1.711 -8.356% 2016-01-06 1.867 1.867 2.695% 2016-01-05 1.818 1.818 -3.143% 2016-01-04 1.877 1.877 -7.945%