某停车场车辆停放服务
收费标准
仅供参考,谢谢
车辆l类型 | 收费方式 | 收费标准 | 备注 | ||
---|---|---|---|---|---|
1小时内停放时间 | 超过免费时间2小时内 | 超过两小时后每小时 | 不足一小时按一小时计算 | ||
小型 | 元/车.次 | 免费 | 3 | 1 |
1、24小时内,车辆连续停放跨两个收费时段的,车辆停放服务
费可累计收取,最高收费不得超过10元;车辆连续停放24小时以上
的,车辆停放服务费按实际停放时间计算。
2、连续停放跨两个收费时段的,可按两个时段的收费标准累加
收取。
3、对正在执行公务或任务的军车、警车、消防车、救灾抢险车、
市政工程(水、电、气、通信、照明、园林绿化等)抢修作业车、
环卫车等特种车辆的停放,免收机动车评放服务费。
Java类
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class ParkingRate {
public String time;//进入时间
public String sumTime;//总时长
public String endTime;//离开时间时间
public double money;//收费金额
public String getTime() {
return time;
}
public String getSumTime() {
return sumTime;
}
public void setSumTime(String sumTime) {
this.sumTime = sumTime;
}
public void setTime(String time) {
// String a = time.replaceAll(time.substring(10,11)," ");
this.time = time;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public double getMoney() throws ParseException {
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = simpleFormat.parse(endTime).getTime() - simpleFormat.parse(time).getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
if(day>0) {
hour = hour + (24 * day);
}
this.sumTime = hour+"小时"+min+"分";
System.out.println(sumTime);
if(hour>=0 && min>=0) {
if(min>0) {
//不足一小时按一小时计价
hour = hour + 1;
}
if(hour==1) {
//一小时内
money = 0.0;
}else if(hour>1 && hour-1<=2) {
//超过免费停车时间2小时内
money = 3.0;
}else if(hour > 3) {
money = 3.0 + (hour-3);
if(hour <=24&& money >10) {
//24小时内不超过10元
money = 10;
}
}
}
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
JSP input.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
计算矩形的面积和周长
method="post">
进入停车时间:"text" name="time" required="required"/>
离开停车时间:"text" name="endTime" required="required"/>
"submit" value="计算" />
parkingRate.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
"Content-Type" content="text/html; charset=UTF-8">
计算停车费
<jsp:useBean id="parkingRate" class="com.bean.类名A" scope="request">jsp:useBean>
<jsp:setProperty property="*" name="parkingRate"/>
进入停车时间:<jsp:getProperty property="time" name="parkingRate"/>
离开停车时间:<jsp:getProperty property="endTime" name="parkingRate"/>
收费金额:<jsp:getProperty property="money" name="parkingRate"/>元
本次停车时长:<jsp:getProperty property="sumTime" name="parkingRate"/>
测试:
1. 2020-04-20 8:00:00至2020-04-20 9:00:00;
2. 2020-04-20 8:00:00至2020-04-20 18:00:00;
3. 2020-04-20 8:00:00至2020-04-22 15:00:00;
计算结果:
Servlet部分
jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
"Content-Type" content="text/html; charset=UTF-8">
计算停车费
测试:
1. 2020-04-20 8:00:00至2020-04-20 9:00:00;
2. 2020-04-20 8:00:00至2020-04-20 18:00:00;
3. 2020-04-20 8:00:00至2020-04-22 15:00:00;
Servlet代码
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/service/parkingFee")
public class ParkingFeeServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
public ParkingFeeServlet() {
super();
// TODO Auto-generated constructor stub
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html; charset=utf-8");
String starTime = req.getParameter("startTime");
String endTime = req.getParameter("endTime");
//生成一个HTML片段
PrintWriter out = resp.getWriter();
out.print("开始停车时间:" + starTime + "
");
out.print("离开时间:" + starTime + "
");
try {
out.print(getMoney(starTime, endTime));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
super.service(arg0, arg1);
}
public String getMoney(String startTime, String endTime) throws ParseException{
double money = 0;
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = simpleFormat.parse(endTime).getTime() - simpleFormat.parse(startTime).getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
if(day>0) {
hour = hour + (24 * day);
}
String sumTime = hour+"小时"+min+"分";
// System.out.println(sumTime);
if(hour>=0 && min>=0) {
if(min>0) {
//不足一小时按一小时计价
hour = hour + 1;
}
if(hour==1) {
//一小时内
money = 0.0;
}else if(hour>1 && hour-1<=2) {
//超过免费停车时间2小时内
money = 3.0;
}else if(hour > 3) {
money = 3.0 + (hour-3);
if(hour <=24&& money >10) {
//24小时内不超过10元
money = 10;
}
}
}
return "本次停车收费金额为:"+ money + "元
停车时长为:" + sumTime;
}
}