java中怎么实现一个停车场管理系统-创新互联
这篇文章给大家介绍java中怎么实现一个停车场管理系统,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
成都创新互联是一家专注于
做网站、网站设计与策划设计,南海网站建设哪家好?
成都创新互联做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:南海等地区。南海做网站价格咨询:18982081108
具体内容如下
//车的类public class car{ public String number;//车牌号 public int inhour; //进入小时 public int inminute; //进入分 public int insecond; //进入秒 public int outhour; //开出小时 public int outminute; //开出分 public int outsecond; //开出秒 public int count; //倒车次数 public car link; //队列的指针//构造方法1 public car(String num){ this.number=num; this.inhour=0; this.inminute=0; this.insecond=0; this.outhour=0; this.outminute=0; this.outsecond=0; int count=0; car link=null; }//构造方法2 public car(){ this.number=""; this.inhour=0; this.inminute=0; this.insecond=0; this.outhour=0; this.outminute=0; this.outsecond=0; int count=0; car link=null; } //成员方法:得到指针 public car getLink(){ return link; } //成员方 法:修改指针 public void setLink(car n){ link=n; } //成员方法;得到车牌号 public String getNum(){ return number;} }++++++++++++++++++++++//停车场基于顺序存储结构 栈//停车场基于顺序存储结构 栈import java.util.Date;public class mylist{ public int Length2; public int Length3; public car[] carStark1; //停车场 public car[] carStark2; //用于倒车的临时栈 //构造方法 public mylist(){ carStark1 =new car[5]; //5个车位的停车场 即栈1 carStark2 =new car[5]; //倒车的临时栈 车位也为5 即栈2 Length2=0; Length3=0; }//入栈 同时将系统时间压入 public void push(String value){ car newcar=new car(value); int n=Length2; carStark1[n]=newcar; Date now = new Date(); //时间类 int hour = now.getHours(); int minute = now.getMinutes(); int second = now.getSeconds(); carStark1[n].inhour=hour; carStark1[n].inminute=minute; carStark1[n].insecond=second; Length2++; } //由栈2回到栈1 public void push3(){ int n=Length2; carStark1[n]=getTop2(); Length2++; Length3--; } //出栈1 入栈2 public void pop(){ car temp =getTop1(); int n=Length3; carStark2[n]=temp; carStark2[n].count++; Length2--; Length3++; } //出栈2 public void pop3(){ Length3--; } //有时间的出栈1 并且暂时入栈2 public void pop2(){ int n=Length2-1; Date now = new Date(); int hour = now.getHours(); int minute = now.getMinutes(); int second = now.getSeconds(); carStark1[n].outhour=hour; carStark1[n].outminute=minute; carStark1[n].outsecond=second; car temp = getTop1(); carStark2[Length3]=temp; Length2--; Length3++; } //得到栈1顶元素 public car getTop1(){ return carStark1[Length2-1]; } //得到栈2顶元素 public car getTop2(){ return carStark2[Length3-1]; } //停车场里有几辆车 public int getLength(){ return Length2; } //获得停车场中第i号车位的车牌号 public String getNum(int i){ return carStark1[i-1].number; }//察看车位情况 public void print(){ int i=0; for(i=0;isize || i<=0) return; locate(i-1); delete(); } //由当前结点到下一个结点 public car getNext(){ if(current == null) return null; current=current.link; return current; } //得到队列的左后一辆车 public car getLast() { while (current.link!=null) { getNext(); } return current; } //由车牌号找到车 public car find(String value){ current=header; while(current.number!=value) { if (current.link==null) { System.out.println("找不到需要的数!!!!"); current=header; break; } current=current.link; } return current; } //取得第m 位置的元素 public car locate(int m ){ if (m > size) return null; current=header; int i; for (i=m;i>0;i--) { getNext(); } return current; } //取得第一个元素 public car getHeader() { return header.link; } //队列里有多少车 public int getLength() { return size; } //察看车位 public void print() { current=header.getLink(); while(current!=null){ int i=1; System.out.print(i+"号车位:"+current.getNum()); System.out.println(" "); i++; getNext(); } } }+++++++++++++++++++++++++//执行程序import java.io.*;import java.lang.*;public class DemoParking{ public mylist parking; //停车场 public myQueue waiting; //队列 public String x1; //选择 public String x2; //开入的车牌号 public String x3; //开出的车牌号 //构造方法 public DemoParking(){ parking=new mylist(); //初始化栈 waiting=new myQueue(); //初始化队列 x1=""; x2=""; x3=""; } // 成员方法:菜单 public void menu(){ System.out.println(" "); System.out.println(" "); System.out.println(" 欢迎进入停车场系统 "); System.out.println("*********************************************"); System.out.println("* 本停车场每秒收费1元 停车场内有5个车位 *"); System.out.println("* 倒车一次返回2元(最少不收费!) *"); System.out.println("*********************************************"); System.out.println(" 1:开进"); System.out.println(" 2:开出"); System.out.println(" 3:车位情况"); System.out.println(" 4:退出"); //+++++++++++++++++++++++++++ System.out.print("请选择:"); try{ BufferedReader keyin = new BufferedReader( new InputStreamReader(System.in)); x1 = keyin.readLine(); } catch (IOException e) { System.out.print("出错了"); } choice(); } //成员方法:选择 public void choice(){ if(x1.equals("1")){ //输入1 开入 System.out.print("请输入车牌号:"); try{ BufferedReader keyin1 = new BufferedReader( new InputStreamReader(System.in)); x2 =new String( keyin1.readLine()); } catch (IOException e){ System.out.print("出错了"); } in(x2); menu(); } if(x1.equals("2")){ //输入2 开出 System.out.print("请输入车牌号:"); try{ BufferedReader keyin1 = new BufferedReader( new InputStreamReader(System.in)); x3 =new String( keyin1.readLine()); } catch (IOException e){ System.out.print("出错了"); } out(x3); } if(x1.equals("3")){ //输入3 查询 Allprint(); menu(); } if(x1.equals("4")){ //输入4 退出 } else{ //输入不符合规定 返回菜单 menu(); } } //成员方法:开入车 public void in(String value){ if (parking.getLength()<5){ //入栈 parking.push(value); System.out.println("*********************************************"); System.out.println("您的车牌号:"+parking.getTop1().number); System.out.println("进入停车场时间:"+parking.getTop1().inhour+":"+parking.getTop1().inminute+":"+parking.getTop1().insecond); System.out.println("*********************************************"); }else{ waiting.insertcar(value); //入队列 } } //成员方法:开出车 public void out(String value){ int i=parking.getLength(); int b=parking.getLength(); //只有栈里有车 查找到开出 if(waiting.getLength()==0){ while(parking.getTop1().number.equals(value)==false){ parking.pop(); //开始倒车 i--; } parking.pop2(); //开出这辆车 进入栈2 System.out.println("*********************************************"); System.out.println(" 您的车牌号:"+parking.getTop2().number); System.out.println(" 进入时间:"+parking.getTop2().inhour+":"+parking.getTop2().inminute+":"+parking.getTop2().insecond); System.out.println(" 离开时间:"+parking.getTop2().outhour+":"+parking.getTop2().outminute+":"+parking.getTop2().outsecond); System.out.println(" 倒车次数:"+parking.getTop2().count); int s=((parking.getTop2().outhour-parking.getTop2().inhour)*60+parking.getTop2().outminute-parking.getTop2().inminute)*60+parking.getTop2().outsecond-parking.getTop2().insecond-2*parking.getTop2().count; System.out.println(" 您的费用:"+s+"元"); System.out.println(" 欢迎下次再来!@_@再见"); System.out.println("*********************************************"); parking.pop3(); //再从栈2中弹出 if(i==b){ }else{ for(int n=i;n0){ //要开出的车在栈里 int c=i; for(;i0){ System.out.println("等待中:"); waiting.print(); } System.out.println("*********************************************"); } public static void main(String[] args)throws IOException{ //应用!! DemoParking demo=new DemoParking(); demo.menu();}}
关于java中怎么实现一个停车场管理系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
当前文章:java中怎么实现一个停车场管理系统-创新互联
分享路径:
http://dzwzjz.com/article/jghhc.html