保存到桌面加入收藏设为首页

 友情提醒上和下均为广告区域 联系QQ:联系爱网络社区


资源分享
当前位置:首页 > 爱网优化 > 资源分享

程序员老黄历怎么用手机程序实现呢?

时间:2018-11-01 12:55:06   作者:爱网络社区   来源:爱网络社区   阅读:1192   评论:0
内容摘要:今早起来,无聊之际把程序员老黄历用Java实现了一番。原JS版地址:http://sandbox.runjs.cn/show/ydp3it7b/尊重原作……哈哈哈(连备注都复制的人是不是很恶心的?)代码如下:packagecom.test;/***activities的枚举*@authorXiao**/publicen...
 今日热门 
胖MM200斤大码女装大毛领棉衣冬装新款韩版宽松显瘦时尚棉服外套 售价:159.00
销量:32
去购买看看
飞利浦PHILIPS无线鼠标可充电式光电静音无声男女生可爱台式电脑小米联想苹果mac笔记本游戏办公家用 售价:39.00
销量:27452
去购买看看
花草茶柠檬片包邮泡茶 柠檬片袋装散装柠檬片 干 烘干柠檬片 泡水 售价:9.90
销量:130
去购买看看
初级会计职称2019教材历年真题试卷全套实务经济法和基础助理会计师2018年会计证章节训练套题练习19年官方正版课本安徽浙江湖南省 售价:35.10
销量:30539
去购买看看
文章出处:爱网络社区
本站网址:http://iwangluo.cn/

更新时间:2018年

投稿邮箱:529502378@qq.com

本站承诺:凡投稿本站的原创稿件,一经采用,随后发送稿费2-20元支付宝现金红包

今早起来,无聊之际把程序员老黄历用Java实现了一番。

原JS版地址:http://sandbox.runjs.cn/show/ydp3it7b/

尊重原作……哈哈哈(连备注都复制的人是不是很恶心的?)

代码如下:

package com.test;
 
/**
 * activities的枚举
 * @author Xiao
 *
 */
public enum ActivitiesEnum {

ACTIVITIES_1("写单元测试", "写单元测试将减少出错", "写单元测试会降低你的开发效率", false),
ACTIVITIES_2("洗澡", "你几天没洗澡了?", "会把设计方面的灵感洗掉", true),
ACTIVITIES_3("锻炼一下身体", "", "能量没消耗多少,吃得却更多", true),
ACTIVITIES_4("抽烟", "抽烟有利于提神,增加思维敏捷", "除非你活够了,死得早点没关系", true),
ACTIVITIES_5("白天上线", "今天白天上线是安全的", "可能导致灾难性后果", false),
ACTIVITIES_6("重构", "代码质量得到提高", "你很有可能会陷入泥潭", false),
ACTIVITIES_7("使用%t", "你看起来更有品位", "别人会觉得你在装逼", false),
ACTIVITIES_8("跳槽", "该放手时就放手", "鉴于当前的经济形势,你的下一份工作未必比现在强", false),
ACTIVITIES_9("招人", "你面前这位有成为牛人的潜质", "这人会写程序吗?", false),
ACTIVITIES_10("面试", "面试官今天心情很好", "面试官不爽,会拿你出气", false),
ACTIVITIES_11("提交辞职申请", "公司找到了一个比你更能干更便宜的家伙,巴不得你赶快滚蛋", "鉴于当前的经济形势,你的下一份工作未必比现在强", false),
ACTIVITIES_12("申请加薪", "老板今天心情很好", "公司正在考虑裁员", false),
ACTIVITIES_13("晚上加班", "晚上是程序员精神最好的时候", "", true),
ACTIVITIES_14("在妹子面前吹牛", "改善你矮穷挫的形象", "会被识破", true),
ACTIVITIES_15("撸管", "避免缓冲区溢出", "强撸灰飞烟灭", true),
ACTIVITIES_16("浏览成人网站", "重拾对生活的信心", "你会心神不宁", true),
ACTIVITIES_17("命名变量%v", "", "", false),
ACTIVITIES_18("写超过%l行的方法", "你的代码组织的很好,长一点没关系", "你的代码将混乱不堪,你自己都看不懂", false),
ACTIVITIES_19("提交代码", "遇到冲突的几率是最低的", "你遇到的一大堆冲突会让你觉得自己是不是时间穿越了", false),
ACTIVITIES_20("代码复审", "发现重要问题的几率大大增加", "你什么问题都发现不了,白白浪费时间", false),
ACTIVITIES_21("开会", "写代码之余放松一下打个盹,有益健康", "小心被扣屎盆子背黑锅", false),
ACTIVITIES_22("打DOTA", "你将有如神助", "你会被虐的很惨", true),
ACTIVITIES_23("晚上上线", "晚上是程序员精神最好的时候", "你白天已经筋疲力尽了", false),
ACTIVITIES_24("修复BUG", "你今天对BUG的嗅觉大大提高", "新产生的BUG将比修复的更多", false),
ACTIVITIES_25("设计评审", "设计评审会议将变成头脑风暴", "人人筋疲力尽,评审就这么过了", false),
ACTIVITIES_26("需求评审", "", "", false),
ACTIVITIES_27("上微博", "今天发生的事不能错过", "今天的微博充满负能量", true),
ACTIVITIES_28("上AB站", "还需要理由吗?", "满屏兄贵亮瞎你的眼", true),
ACTIVITIES_29("玩FlappyBird", "今天破纪录的几率很高", "除非你想玩到把手机砸了", true);

private String name;
private String good;
private String bad;
private Boolean weekend;

ActivitiesEnum(String name, String good, String bad, Boolean weekend){
this.setBad(bad);
this.setGood(good);
this.setName(name);
this.setWeekend(weekend);
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGood() {
return good;
}
public void setGood(String good) {
this.good = good;
}
public String getBad() {
return bad;
}
public void setBad(String bad) {
this.bad = bad;
}
public Boolean getWeekend() {
return weekend;
}
public void setWeekend(Boolean weekend) {
this.weekend = weekend;
}
}


package com.test;
 
public enum SpecialsEnum {

SPECIALS(2014, "bad", "待在男(女)友身边", "脱团火葬场,入团保平安。");

private Integer date;
private String type;
private String name;
private String description;

SpecialsEnum (Integer date, String type, String name, String description){
this.setDate(date);
this.setType(type);
this.setName(name);
this.setDescription(description);
}

public Integer getDate() {
return date;
}
public void setDate(Integer date) {
this.date = date;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}

}

package com.test;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
 
import org.apache.commons.lang.StringUtils;
 
public class ProgrammerCalendar {
private Integer iday = 0;

private String [] weeks = new String[]{"日", "一","二","三","四","五","六"};
private String [] directions = new String[]{"北方","东北方","东方","东南方","南方","西南方","西方","西北方"};
private String [] tools =  new String[]{"Eclipse写程序", "MSOffice写文档", "记事本写程序", "Windows8", "Linux", "MacOS", "IE", "Android设备", "iOS设备"};
private String [] varNames  =  new String[]{"jieguo", "huodong", "pay", "expire", "zhangdan", "every", "free", "i1", "a", "virtual", "ad", "spider", "mima", "pass", "ui"};
private String [] drinks  =  new String[]{"水","茶","红茶","绿茶","咖啡","奶茶","可乐","鲜奶","豆奶","果汁","果味汽水","苏打水","运动饮料","酸奶","酒"};

public Integer getIday() {
return iday;
}
 
public String[] getDirections() {
return directions;
}
 
/*
* 注意:本程序中的“随机”都是伪随机概念,以当前的天为种子。
*/
public Integer random(Integer daySeed, Integer indexSeed) {
Integer n = daySeed % 11117;
for (int i = 0; i < 100 + indexSeed; i++) {
n = n * n;
n = n % 11117; //11117是个质数
}
return n;
}

public String getTodayString (){
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
return "今天是" + calendar.get(Calendar.YEAR) + "年" + (calendar.get(Calendar.MONTH) + 1) 
+ "月" + calendar.get(Calendar.DAY_OF_MONTH) 
+ "日 星期" + weeks[calendar.get(Calendar.DAY_OF_WEEK) - 1];
}

public String star(Integer num) {
String result = "";
int i = 0;
while (i < num) {
result += "★";
i++;
}
while(i < 5) {
result += "☆";
i++;
}
return result;
}

private Boolean isWeekend() {
Locale.setDefault(Locale.CHINA);
Calendar calendar = Calendar.getInstance();
return calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7;
}

public List<ActivitiesEnum> filter() {
List<ActivitiesEnum> thisEnum = new ArrayList<ActivitiesEnum>();

   // 周末的话,只留下 weekend = true 的事件
if(isWeekend()) {
for (ActivitiesEnum e : ActivitiesEnum.values()) {
if(e.getWeekend()){
thisEnum.add(e);
}
}
return thisEnum;
}
return new ArrayList<ActivitiesEnum>(Arrays.asList(ActivitiesEnum.values()));
}

public void pickTodaysLuck() {
List<ActivitiesEnum> _activities = filter();

Integer numGood = random(iday, 98) % 3 + 2;
Integer numBad = random(iday, 87) % 3 + 2;
List<Map<String, String>> eventArr = pickRandomActivity(_activities, numGood + numBad);

Integer [] specialSize = pickSpecials();

System.out.println("宜:");
for (int i = 0; i < numGood; i++) {
System.out.println("    " + eventArr.get(i).get("name") + (StringUtils.isNotBlank(eventArr.get(i).get("good")) ? ":" + eventArr.get(i).get("good") : ""));
}
System.out.println("不宜:");
for (int i = 0; i < numBad; i++) {
System.out.println("    " + eventArr.get(numGood + i).get("name") + (StringUtils.isNotBlank(eventArr.get(numGood + i).get("bad")) ? ":" + eventArr.get(numGood + i).get("bad") : ""));
}
}

/**
* 从数组中随机挑选 size 个
* @param size
* @return
*/
private List<ActivitiesEnum> pickRandom(List<ActivitiesEnum> _activities, Integer size) {
List<ActivitiesEnum> result = new ArrayList<ActivitiesEnum>();

for (ActivitiesEnum ae : _activities) {
result.add(ae);
}

for (int i = 0; i < _activities.size() - size; i++) {
int index = random(iday, i) % result.size();
result.remove(index);
}
return result;
}

/**
* 从数组中随机挑选 size 个
* @param size
* @return
*/
private List<String> pickRandomDrinks(Integer size) {
List<String> result = new ArrayList<String>(Arrays.asList(drinks));

for (int i = 0; i < drinks.length - size; i++) {
int index = random(iday, i) % result.size();
result.remove(index);
}
return result;
}
 
//  枚举 中随机挑选 size 个
public List<Map<String, String>> pickRandomActivity(List<ActivitiesEnum> _activities, Integer size) {
List<ActivitiesEnum> picked_events = pickRandom(_activities, size);
List<Map<String, String>> mapList = new ArrayList<Map<String,String>>();
for (int i = 0; i < picked_events.size(); i++) {
mapList.add(parse(picked_events.get(i)));
}
return mapList;
}

/**
* 解析占位符并替换成随机内容
* @param ae
* @return
*/
public Map<String, String> parse(ActivitiesEnum ae) {
Map<String, String> map = new HashMap<String, String>();
map.put("name", ae.getName());
map.put("good", ae.getGood());
map.put("bad", ae.getBad());

if(map.get("name").indexOf("%v") != -1) {
map.put("name", map.get("name").replaceAll("%v", varNames[random(iday, 12) % varNames.length]));
}
if(map.get("name").indexOf("%t") != -1) {
map.put("name", map.get("name").replaceAll("%t", tools[random(iday, 11) % tools.length]));
}
if(map.get("name").indexOf("%t") != -1) {
map.put("name", map.get("name").replaceAll("%l", (random(iday, 12) % 247 + 30) + ""));
}
return map;
}

public Integer [] pickSpecials () {
Integer [] specialSize = new Integer[]{0, 0};
for (SpecialsEnum se : SpecialsEnum.values()) {
if(iday == se.getDate()){
if(se.getType().equals("good")){
specialSize[0]++;
}else{
specialSize[1]++;
}
System.out.println("name:" + se.getName() + " description:" + se.getDescription());
}
}
return specialSize;
}

public ProgrammerCalendar() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
try {
iday = Integer.parseInt(sdf.format(new Date()));
} catch (Exception e) {
e.printStackTrace();//懒得引用log了
}
}

public static void main(String[] args) {
ProgrammerCalendar hl = new ProgrammerCalendar();
System.out.println("今天是:" + hl.getTodayString());
System.out.println("座位朝向:面向" + hl.directions[hl.random(hl.getIday(), 2) % hl.getDirections().length] + "写程序,BUG 最少。");
System.out.println("今日宜饮:" + StringUtils.join(hl.pickRandomDrinks(2), ","));
System.out.println("女神亲近指数:" + hl.star(hl.random(hl.getIday(), 6) % 5 + 1));
hl.pickTodaysLuck();
}

--------------------- 
作者:Sean-Xiao 
来源:CSDN 
原文:https://blog.csdn.net/demonxyy/article/details/52659165 
版权声明:本文为博主原创文章,转载请附上博文链接!
* 所有教程和软件仅供参考和学习 投稿者并非本站官网人员 爱网络社区有权关闭不遵纪守法用户。
* 本站教程种类繁多 用的好麻烦点分享!
* 破解软件或黑客软件存在误报可能 小爱也都是亲测可用 如果不放心可以别下载 不要BB!

* 站内提供的所有软件包含破解及注册码均是由网上搜集,若侵犯了你的版权利益,敬请529502378通知我们!



标签:程序员老黄历  
相关评论
本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除

投稿邮箱:529502378@qq.com 商务合作QQ529502378

官方网址:http://iwangluo.cn Copyright ?2017 - 2018 爱网络社区ALL RIGHT RESERVED |


  晋ICP备18001688号-2