I woke up this morning and realized the programmer's old almanac in Java when I was bored.
Original JS version address: Programmer Lao Huang Li
Respect the original work... Hahaha (Is it disgusting for people who even copy the notes?)
The code is as follows:
Code Snippet 1
package com.test; /** * Enumeration of activities* @author Xiao * */ public enum ActivitiesEnum { ACTIVITIES_1("Write unit test", "Write unit tests will reduce errors", "Write unit tests will reduce your development efficiency", false), ACTIVITIES_2("Take a bath", "How many days have you not taken a bath?", "Will wash away the design inspiration", true), ACTIVITIES_3("Exercise the body", "", "Don't consume much energy, but eat more", true), ACTIVITIES_4("Smoking", "Smoking is good for refreshing and increasing your thinking agility", "Unless you have lived enough, it doesn't matter if you die early", true), ACTIVITIES_5("online during the day", "It's safe to go online today during the day", "Can cause catastrophic consequences", false), ACTIVITIES_6("Refactor", "Code quality is improved", "You are likely to fall into the quagmire", false), ACTIVITIES_7("Use %t", "You look more tasteful", "Others will think you are pretending", false), ACTIVITIES_8("Cross job", "Let go when it's time to let go", "Given the current economic situation, your next job may not be better than now", false), ACTIVITIES_9("Recruiting", "The person in front of you has the potential to become a great man", "Is this person able to write a program?", false), ACTIVITIES_10("Interview", "The interviewer is in a good mood today", "The interviewer is unhappy and will vent your anger", false), ACTIVITIES_11("Submit an application for resignation", "The company has found someone who is more capable than you, you should get out of here", "Given the current economic situation, your next job may not be better than now", false), ACTIVITIES_12("Apply for a salary increase", "The boss is in a good mood today", "The company is considering layoffs", false), ACTIVITIES_13("Work overtime at night", "The evening is the best time for programmers to be energetic", "", true), ACTIVITIES_14("Brave in front of girls", "Improve your short and poor image", "I will be seen through", true), ACTIVITIES_15("Masturbate", "Avoid buffer overflow", true), ACTIVITIES_16("Browse adult websites", "Regain confidence in life", "You will be restless", true), ACTIVITIES_17("Name variable %v", "", "", "", false), ACTIVITIES_18("Works to write more than %l lines", "Your code is well organized, it doesn't matter if it's longer", "Your code will be in a mess, you won't even understand it yourself", false), ACTIVITIES_19("Submit code", "The chance of encountering conflicts is the lowest", "The many conflicts you encounter will make you feel that you have traveled through time", false), ACTIVITIES_20("Code review", "The chance of finding important problems is greatly increased", "You can't find any problem, waste time in vain", false), ACTIVITIES_21("Settle meeting", "Relax and take a nap while writing code, good for health", false), ACTIVITIES_22("Dota", "You will be like God's help", "You will be abused very badly", true), ACTIVITIES_23("Let's go online at night", "The evening is the best time for programmers to be energetic", "You are exhausted during the day", false), ACTIVITIES_24("Fix the bug", "You have a great sense of smell about bugs today", "The new bugs will be more than fixed", false), ACTIVITIES_25("Design review", "The design review meeting will become a brainstorm", "Everyone is exhausted, the review is just passed", false), ACTIVITIES_26("Demand review", "", "", false), ACTIVITIES_27("On Weibo", "You can't miss what happened today", "Today's Weibo is full of negative energy", true), ACTIVITIES_28("On AB website", "Do you need a reason?", "Brother Baiping is blinding your eyes", true), ACTIVITIES_29("Play FlappyBird", "The chance of breaking the record today is very high", "Unless you want to play until you smash your phone", 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; } }Code Snippet 2
package com.test; public enum SpecialsEnum { SPECIALS(2014, "bad", "stay with your boyfriend (female) friends", "Leave the crematorium and join the group to ensure safety."); 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; } }Code Snippet 3
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[]{"day", "one", "two", "three", "four", "five", "six"}; private String [] directions = new String[]{"North", "northeast", "east", "southeast", "southwest", "northwest"}; private String [] tools = new String[]{"Eclipse Write Program", "MSOffice Write Documents", "Notepad Write Programs", "Windows8", "Linux", "MacOS", "IE", "Android Device", "iOS device"}; 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[]{"water","tea","black tea","green tea","coffee","milk tea","cola","fresh milk","soy milk","juice","fruit soda","soda water","sports drinks","yogurt","wine"}; public Integer getIday() { return iday; } public String[] getDirections() { return directions; }/** * Note: The "random" in this program is all pseudo-random concepts, with the current day as the seed. */ 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 is a prime number} return n; } public String getTodayString (){ Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); return "Today is" + calendar.get(Calendar.YEAR) + "Year" + (calendar.get(Calendar.MONTH) + 1) + "month" + calendar.get(Calendar.DAY_OF_MONTH) + "Day and Week" + 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>(); // For weekends, only weekend = true event 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(day, 87) % 3 + 2; List<Map<String, String>> eventArr = pickRandomActivity(_activities, numGood + numBad); Integer [] specialSize = pickSpecials(); System.out.println("Yes:"); 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("not suitable:"); 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") : "")); } } /** * Randomly select sizes from the array * @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(day, i) % result.size(); result.remove(index); } return result; } /** * Randomly select sizes from the array * @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(day, i) % result.size(); result.remove(index); } return result; } // Randomly select 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; } /** * Parses the placeholder and replace it with random content* @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(day, 12) % varNames.length])); } if(map.get("name").indexOf("%t") != -1) { map.put("name", map.get("name").replaceAll("%t", tools[random(day, 11) % tools.length])); } if(map.get("name").indexOf("%t") != -1) { map.put("name", map.get("name").replaceAll("%l", (random(day, 12) % 247 + 30) + "")); } return map; } public Integer [] pickSpecials () { Integer [] specialSize = new Integer[]{0, 0}; for (SpecialsEnum se : SpecialsEnum.values()) { if(day == se.getDate()) { if(day == 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();//I'm too lazy to refer to log} } public static void main(String[] args) { ProgrammerCalendar hl = new ProgrammerCalendar(); System.out.println("Today is:" + hl.getTodayString()); System.out.println("Seat orientation: facing" + hl.directions[hl.random(hl.getIday(), 2) % hl.getDirections().length] + "Write program, with the least bugs."); System.out.println("Today's drink:" + StringUtils.join(hl.pickRandomDrinks(2), ",")); System.out.println("Goddess's closeness index:" + hl.star(hl.random(hl.getIday(), 6) % 5 + 1)); hl.pickTodaysLuck(); } }Running results:
Today is: Today is Sunday, September 25, 2016. Seat orientation: Writing programs to the west, with the least bugs.
Today's drink: Coke, Juice Goddess's closeness index: ★★☆☆☆
should:
Exercise your body and work overtime at night: Evening is the best time for programmers to browse adult websites: It is not appropriate to regain confidence in life:
Playing DOTA: You will be abused so badly on AB: Brother Man Ping blinds your eyes
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support to Wulin.com.