软件工程师上班时如何度过艰难的下午(15:00~16:00)

1.交替活动。早上编码,那么下午可以采取:到实验室调试,开会,与同事讨论,找个适当的地方听5~10分钟适合的音乐,练下马步等运动,甚至是到办公楼下逛5分钟。
重要的是大脑一定要交替活动。不能太长时间(超过4小时)连续地思考同一问题。
其实,最重要的就是早上时就要准备好几个不同类型的问题,然后早上解决一个,下午解决一个,这样很完美。
讨论的好处是:让软工获得说话的机会,而且两个人一起讨论,会使问题变得有趣。


2.营养:运动,健康,音乐,吃东西

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是实现上述需求的Java代码: ```java import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class CarRentalBilling { // 定义间段及对应的计费费率 private Map<String, BigDecimal> rateMap; public CarRentalBilling() { rateMap = new HashMap<>(); rateMap.put("00:00~03:00", new BigDecimal("3")); rateMap.put("03:00~09:00", new BigDecimal("5")); rateMap.put("09:00~12:00", new BigDecimal("10")); rateMap.put("15:00~24:00", new BigDecimal("15")); } /** * 计算停车费用 * * @param startTime 开始间,格式为"yyyy-MM-dd HH:mm" * @param endTime 结束间,格式为"yyyy-MM-dd HH:mm" * @return 停车费用 */ public BigDecimal calculateFee(String startTime, String endTime) throws ParseException { // 将间字符串转换为Date类型 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date start = sdf.parse(startTime); Date end = sdf.parse(endTime); // 按天分割间段 List<Date[]> timeSegments = splitTimeSegment(start, end); // 计算每个间段的费用 BigDecimal totalFee = BigDecimal.ZERO; for (Date[] segment : timeSegments) { totalFee = totalFee.add(calculateSegmentFee(segment[0], segment[1])); } return totalFee; } /** * 分割间段,考虑跨天的情况 * * @param start 开始间 * @param end 结束间 * @return 间段列表 */ private List<Date[]> splitTimeSegment(Date start, Date end) { List<Date[]> timeSegments = new ArrayList<>(); // 如果结束间早于开始间,表示跨天 if (end.before(start)) { Calendar calendar = Calendar.getInstance(); calendar.setTime(end); calendar.add(Calendar.DATE, 1); // 结束间加一天 end = calendar.getTime(); } // 分割间段 Calendar calendar = Calendar.getInstance(); calendar.setTime(start); while (calendar.getTime().before(end)) { Date segmentStart = calendar.getTime(); calendar.add(Calendar.HOUR_OF_DAY, 1); Date segmentEnd = calendar.getTime(); timeSegments.add(new Date[]{segmentStart, segmentEnd}); } return timeSegments; } /** * 计算每个间段的费用 * * @param start 间段开始间 * @param end 间段结束间 * @return 间段费用 */ private BigDecimal calculateSegmentFee(Date start, Date end) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); String startStr = sdf.format(start); String endStr = sdf.format(end); BigDecimal fee = BigDecimal.ZERO; for (Map.Entry<String, BigDecimal> entry : rateMap.entrySet()) { String[] timeRange = entry.getKey().split("~"); String startRange = timeRange[0]; String endRange = timeRange[1]; // 判断间段是否在指定的范围内 if (isInRange(startStr, endStr, startRange, endRange)) { BigDecimal rate = entry.getValue(); long hours = getHourDifference(start, end); fee = rate.multiply(BigDecimal.valueOf(hours)); break; } } return fee; } /** * 判断间段是否在指定的范围内 * * @param start 间段开始间 * @param end 间段结束间 * @param startRange 指定范围的开始间 * @param endRange 指定范围的结束间 * @return 是否在指定范围内 */ private boolean isInRange(String start, String end, String startRange, String endRange) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); try { Date startTime = sdf.parse(start); Date endTime = sdf.parse(end); Date startRangeTime = sdf.parse(startRange); Date endRangeTime = sdf.parse(endRange); return (startTime.equals(startRangeTime) || startTime.after(startRangeTime)) && (endTime.equals(endRangeTime) || endTime.before(endRangeTime)); } catch (ParseException e) { e.printStackTrace(); } return false; } /** * 计算两个间点之间的小差 * * @param start 开始间 * @param end 结束间 * @return 小差 */ private long getHourDifference(Date start, Date end) { long diff = end.getTime() - start.getTime(); return diff / (60 * 60 * 1000); } public static void main(String[] args) throws ParseException { CarRentalBilling carRentalBilling = new CarRentalBilling(); BigDecimal fee = carRentalBilling.calculateFee("2022-07-11 12:00", "2022-07-12 16:00"); System.out.println("停车费用:" + fee + "元"); } } ``` 这段代码实现了按间段计费的需求,考虑了跨夜和间段断层的情况。具体实现步骤如下: 1. 首先定义了间段及对应的计费费率,使用`rateMap`保存。 2. `calculateFee`方法用于计算停车费用,接收开始间和结束间,并返回停车费用。在方法中,首先将间字符串转换为`Date`类型。 3. `splitTimeSegment`方法用于分割间段,考虑跨天的情况。如果结束间早于开始间,表示跨天,需要将结束间加一天。然后,使用循环和`Calendar`类将间段按每小分割,并保存到`timeSegments`列表中。 4. `calculateSegmentFee`方法用于计算每个间段的费用。根据间段的开始间和结束间,遍历`rateMap`中的每个间段,判断间段是否在指定的范围内。如果是,则根据计费费率和小差计算费用。 5. `isInRange`方法用于判断间段是否在指定的范围内。首先将间字符串转换为`Date`类型,然后比较开始间和结束间是否在指定范围内。 6. `getHourDifference`方法用于计算两个间点之间的小差。 7. 在`main`方法中,创建`CarRentalBilling`对象,并调用`calculateFee`方法计算停车费用,最后输出结果。 请注意,以上代码仅供参考,具体实现可能需要根据实际需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值