计算4

发布时间:2017-6-29 10:00:46编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"计算4",主要涉及到计算4方面的内容,对于计算4感兴趣的同学可以参考一下。

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class QianbaoTask4 {


    public static float constantRate = (float) 0.0004;
    public static float floatingRate = (float) 0.0006;
    public static float ticketRate = (float) 0.0036;


    public static void main(String[] args) {
        
        List<String> account1Changelist = new ArrayList<String>();
//        account1Changelist.add("2017-04-17,1357753,38793,capital");
//        account1Changelist.add("2017-04-21,21862,0,task");
//        account1Changelist.add("2017-04-22,1020,2040,task");
//        account1Changelist.add("2017-04-23,2208,4395,task");
//        account1Changelist.add("2017-05-02,16604,0,task");
//        account1Changelist.add("2017-05-03,-386000,0,capital");
//        account1Changelist.add("2017-05-06,11000,0,capital");
//        account1Changelist.add("2017-05-07,23962,0,task");
//        account1Changelist.add("2017-05-10,1081723,153283,capital");
//        account1Changelist.add("2017-05-20,930000,0,capital");
//        account1Changelist.add("2017-05-21,597600,0,capital");
//        account1Changelist.add("2017-05-26,-1200000,0,capital");
//        account1Changelist.add("2017-05-27,1293848,0,capital");
//        account1Changelist.add("2017-06-01,2744381,305701,capital");
//        account1Changelist.add("2017-06-02,80000,0,capital");
//        account1Changelist.add("2017-06-06,-1340000,0,capital");
        account1Changelist.add("2017-06-11,1506708,388210,capital");
        account1Changelist.add("2017-06-12,60000,0,capital");

        List<String> account2Changelist = new ArrayList<String>();
//        account2Changelist.add("2017-04-17,460000,0,capital");
//        account2Changelist.add("2017-05-03,661842,0,capital");
        
//        account2Changelist.add("2017-05-10,1138883,55290,capital");
//        account2Changelist.add("2017-05-15,-824,0,capital");
//        account2Changelist.add("2017-06-01,1162664,146368,capital");
//        account2Changelist.add("2017-06-02,-824,0,capital");
//        account2Changelist.add("2017-06-05,22252,0,task");
        account2Changelist.add("2017-06-11,1195573,188865,capital");
        account2Changelist.add("2017-06-12,-60000,0,capital");
        account2Changelist.add("2017-06-17,33888,0,task");
        
        List<AccountTask> account1TaskList = new ArrayList<AccountTask>();
        List<AccountTask> account2TaskList = new ArrayList<AccountTask>();
        
        float totalMoney = 0;
        float totalTicket = 0;
        float account1Money = 0;
        float account2Money = 0;
        float account1Ticket = 0;
        float account2Ticket = 0;
        
        float account1RewardMoney = 0;
        float account2RewardMoney = 0;
        float account1RewardTicket = 0;
        float account2RewardTicket = 0;
        
        for (String value : account1Changelist) {
            String[] tmp = value.split(",");
            AccountTask accountTask = new AccountTask(tmp[0], Integer.valueOf(tmp[1]), Integer.valueOf(tmp[2]), tmp[3]);
            account1TaskList.add(accountTask);
        }


        for (String value : account2Changelist) {
            String[] tmp = value.split(",");
            AccountTask accountTask = new AccountTask(tmp[0], Integer.valueOf(tmp[1]), Integer.valueOf(tmp[2]), tmp[3]);
            account2TaskList.add(accountTask);
        }


        System.out.println("**********Accout 1************");
        Map<String, Float> account1Result = calculateAccountProfit(account1TaskList, account1Money, account1Ticket,account1RewardMoney,account1RewardTicket);
        
        account1Money = account1Result.get("money");
        account1Ticket = account1Result.get("ticket");
        account1RewardMoney = account1Result.get("rewardMoney");
        account1RewardTicket = account1Result.get("rewardTicket");
        


        System.out.println("**********Accout 2************");
        Map<String, Float> account2Result = calculateAccountProfit(account2TaskList, account2Money, account2Ticket,account2RewardMoney,account2RewardTicket);
        
        account2Money = account2Result.get("money");
        account2Ticket = account2Result.get("ticket");
        account2RewardMoney = account2Result.get("rewardMoney");
        account2RewardTicket = account2Result.get("rewardTicket");
        
        
        totalMoney = account1Money + account2Money;
        totalTicket = account1Ticket + account2Ticket;
        
        System.out.println("totalMoney: " + totalMoney);
        System.out.println("totalTicket: " + totalTicket);        
        System.out.println("account1Money: " + account1Money);
        System.out.println("account2Money: " + account2Money);
        System.out.println("account1Ticket: " + account1Ticket);
        System.out.println("account2Ticket: " + account2Ticket);
        System.out.println("account1RewardMoney: " + account1RewardMoney);
        System.out.println("account2RewardMoney: " + account2RewardMoney);
        System.out.println("account1RewardTicket: " + account1RewardTicket);
        System.out.println("account2RewardTicket: " + account2RewardTicket);
        
    }


    public static int getIntervalDays(Date fDate, Date oDate) {
        if (null == fDate || null == oDate) {
            return -1;
        }
        long intervalMilli = oDate.getTime() - fDate.getTime();
        return (int) (intervalMilli / (24 * 60 * 60 * 1000));
    }


    // calculate the current one day profit
    public static Map<String, Float> calculateCurrenDay(float money, float ticket, float rewardMoney,
            float rewardTicket, String source, int changeMoney, int changeTicket) {
        
        Map<String, Float> resultMap = new HashMap<String, Float>();
        float todayMoney =0;
        float todayTicket = 0;
        float todayRewardMoney = 0;
        float todayRewardTicket = 0;
        boolean hasReward = true;
        
        System.out.println("前一天资金总量:" + money + ", 前一天宝券总量: " + ticket + ", 今天的资金变化: " + changeMoney + ", 今天的宝券变化:" + changeTicket);
        
        if (changeMoney >= 0) {
            // 1)加仓的时候,先充值,再签到;
            // 2)任务完成的时候,先加上收益,再签到,再加上任务的宝券收益
            // 3)用宝券购物的时候,减去宝券,不影响签到的前后顺序
            money += changeMoney;
            ticket += changeTicket;


            todayMoney = money * (constantRate + floatingRate);
            todayTicket = money * ticketRate;
            
            System.out.println("今天的签到资金收益: "+todayMoney +", 今天的签到宝券收益: "+todayTicket);
            
            money += todayMoney;
            ticket += todayTicket;
            
        } else {
            // 1)减仓的时候,先签到,再提现;
            // 2)如果用钱宝币购物的时候,要先签到,再减去钱宝币


            todayMoney = money * (constantRate + floatingRate);
            todayTicket = money * ticketRate;


            System.out.println("今天的签到资金收益: "+todayMoney +", 今天的签到宝券收益: "+todayTicket);
            
            money += todayMoney;
            ticket += todayTicket;


            money += changeMoney;
            ticket += changeTicket;
            
            if(changeMoney*(-1)>todayMoney){
                hasReward = false;
            }
        }
        
        if (hasReward) {
            if (source.equals("task")) {
                todayRewardMoney = (float) ((changeMoney + todayMoney) * 0.018);
                todayRewardTicket = todayRewardMoney * 100;
            } else {
                todayRewardMoney = (float) (todayMoney * 0.018);
                todayRewardTicket = todayRewardMoney * 100;
            }
        }
        
        float accountMaintenanceFee = (float) (0.01 / 365 * money);
        money -= accountMaintenanceFee;
        
        System.out.println("今天账户管理费:" + accountMaintenanceFee);
        
        rewardMoney += todayRewardMoney;
        rewardTicket += todayRewardTicket;
        
        resultMap.put("money", money);
        resultMap.put("ticket", ticket);
        resultMap.put("rewardMoney", rewardMoney);
        resultMap.put("rewardTicket", rewardTicket);
        
        System.out.println("今天资金总量:" + money + ", 今天宝券总量: " + ticket);
        System.out.println("今天推广收益宝币:" + todayRewardMoney + ", 今天推广收益宝券:" + todayRewardTicket + ", 推广收益宝币总量:" + rewardMoney
                + ", 推广收益宝券总量:" + rewardTicket);
        System.out.println();
        return resultMap;
    }


    public static Map<String, Float> calculateAccountProfit(List<AccountTask> accountTaskList, float accountMoney,
            float accountTicket, float accountRewardMoney, float accountRewardTicket) {


        Map<String, Float> resultMap = new HashMap<String, Float>();


        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");


            // calculate account profit
            for (int i = 0; i < accountTaskList.size() - 1; i++) {
                
                System.out.println(accountTaskList.get(i).accountChangeDate);
                Date count1DayFrom = sdf.parse(accountTaskList.get(i).accountChangeDate);
                
                Map<String, Float> resultMap1 = calculateCurrenDay(accountMoney, accountTicket, accountRewardMoney,
                        accountRewardTicket, accountTaskList.get(i).source, accountTaskList.get(i).accountChangeMoney,
                        accountTaskList.get(i).accountChangeTicket);
                
                accountMoney = resultMap1.get("money");
                accountTicket = resultMap1.get("ticket");
                accountRewardMoney = resultMap1.get("rewardMoney");
                accountRewardTicket= resultMap1.get("rewardTicket");
                
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(count1DayFrom);
                
                Date count1DayTo = sdf.parse(accountTaskList.get(i + 1).accountChangeDate);
                int periodDays = getIntervalDays(count1DayFrom, count1DayTo);


                for (int j = 0; j < periodDays-1; j++) {
                    calendar.add(Calendar.DAY_OF_MONTH, 1);
                    System.out.println(sdf.format(calendar.getTime()));
                    Map<String, Float> periodResultMap1 = calculateCurrenDay(accountMoney, accountTicket, accountRewardMoney,
                            accountRewardTicket, "capital", 0, 0);
                    accountMoney = periodResultMap1.get("money");
                    accountTicket = periodResultMap1.get("ticket");
                    accountRewardMoney = periodResultMap1.get("rewardMoney");
                    accountRewardTicket= periodResultMap1.get("rewardTicket");
                }
            }


            System.out.println(accountTaskList.get(accountTaskList.size() - 1).accountChangeDate);
            
            Date count1DayLastFrom = sdf.parse(accountTaskList.get(accountTaskList.size() - 1).accountChangeDate);


            Map<String, Float> resultMap1 = calculateCurrenDay(accountMoney, accountTicket, accountRewardMoney,
                    accountRewardTicket, accountTaskList.get(accountTaskList.size() - 1).source,
                    accountTaskList.get(accountTaskList.size() - 1).accountChangeMoney,
                    accountTaskList.get(accountTaskList.size() - 1).accountChangeTicket);
            accountMoney = resultMap1.get("money");
            accountTicket = resultMap1.get("ticket");
            accountRewardMoney = resultMap1.get("rewardMoney");
            accountRewardTicket= resultMap1.get("rewardTicket");
            
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(count1DayLastFrom);
            
            Date count1DayLastTo = new Date();
            int lastPeriodDays1 = getIntervalDays(count1DayLastFrom, count1DayLastTo);
            for (int j = 0; j < lastPeriodDays1; j++) {
                calendar.add(Calendar.DAY_OF_MONTH, 1);
                System.out.println(sdf.format(calendar.getTime()));
                Map<String, Float> lastPeriodResultMap1 = calculateCurrenDay(accountMoney, accountTicket,
                        accountRewardMoney, accountRewardTicket, "capital", 0, 0);
                accountMoney = lastPeriodResultMap1.get("money");
                accountTicket = lastPeriodResultMap1.get("ticket");
                accountRewardMoney = lastPeriodResultMap1.get("rewardMoney");
                accountRewardTicket= lastPeriodResultMap1.get("rewardTicket");
            }


        } catch (Exception e) {
            e.getMessage();
        }
        resultMap.put("money", accountMoney);
        resultMap.put("ticket", accountTicket);
        resultMap.put("rewardMoney", accountRewardMoney);
        resultMap.put("rewardTicket", accountRewardTicket);
        return resultMap;
    }


}



上一篇:高性能Mysql笔记 (4) -
下一篇:Install tensorflow and test

相关文章

关键词: 计算4

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款