能够同时进出车 可直接运行的基于Java多线程的停车场管理系统( 四 )

< flag; i++) {orderNumbers1[i] = orderNumbers[i];}exit(orderNumbers1);}//获取车库内车库的信息private void searchAll() {for (Transaction transaction : lists) {String flag = ("订单号:" + transaction.getOrderNumber() + " 入库时间:" + transaction.getEnterStime() + transaction.getCar().toString());System.out.println(flag);}}//用于判定用户输入的内容是否合法(int类型的)private int testInput() {Scanner sc = new Scanner(System.in);String input = sc.next();if (input == null || input.length() == 0) {return -3;}int number = 0;int mark = 0; //帮助循环标记第一位int var = 0; //表示正负char[] chars = input.toCharArray();//判断正负数//if(chars[0] == "-")这一段可以放在后面,但是为了方便循环if (chars[0] == '-' || chars[0] == '+') {mark = 1;if (chars[0] == '-')var = 1;}//此处i不能单纯的从0开始,要么对第一位的+-做判断,要么在前面就解决for (int i = mark; i < input.length(); i++) {if (chars[i] < 48 || chars[i] > 57) {return -3;}number = number * 10 + chars[i] - 48;//注意与真正数字切换}return var == 1 ? -number : number;}//读取文本(也就是已经出库的订单信息)private static void readFile() {String pathname = "d:/hell.txt";try (FileReader reader = new FileReader(pathname);BufferedReader br = new BufferedReader(reader) // 建立一个对象,它把文件内容转成计算机能读懂的语言) {String line;while ((line = br.readLine()) != null) {System.out.println(line);}} catch (IOException e) {e.printStackTrace();}}//内部类public static class SerializableTest {//用于出库的车的账单的查询//传入需要写入文件的订单信息(参数为Transaction类)private static void serializecar(Transaction m) throws IOException {ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("d:/hell.txt"), true));oos.writeObject(m.exitWay() + "\n");oos.close();}//将车库内的车写入文件,避免系统关闭之后信息丢失private static void serializecar1(Object object) throws IOException {//传入需要写入文件的transaction 类ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("d:/hell12.txt")));oos.writeObject(object);oos.close();oos.flush();}//读取上次系统关闭之后还未出库的汽车private static ArrayList deserializecar1() throws Exception {ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("d:/hell12.txt")));ArrayList arr1 = new ArrayList();arr1 = (ArrayList) ois.readObject();return arr1;}//获取订单号private static void serializecarint(int m) throws IOException {//传入intObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("d:/int.txt")));oos.writeObject(m);oos.close();}//保存订单号private static int deserializecar1int() throws Exception {ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("d:/int.txt")));int arr1;arr1 = (int) ois.readObject();return arr1;}}}
类(测试类):
package BigTest;public class programRun {public static void main(String[] args) {//创建一个Park的实例Park p1 = Park.getInstance();//打印菜单p1.Menu();}}
运行示例:
停车:
查看车信息:
出库并缴费:
查看所有出库的车的信息(不知道什么原因,开头都是莫名其妙的乱码,但是我的信息是完整的):
总结
将代码复制到编译器中,修改一下包名即可测试并使用,有错误或者说错的地方欢迎大家指正,出库与入库都是使用的内部类的线程,所以你们会发现有时候主线程已经打印了菜单而分线程才执行完出库/入库/打印订单的操作 。
【能够同时进出车可直接运行的基于Java多线程的停车场管理系统】(如果觉得本篇文章对你用处较大,请点个赞再走呗~)