import java.util.ArrayList; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.List; import java.util.Scanner; import java.util.Iterator;
//异常类 class aException extends Exception{ private String message; public aException(String message) { this.message=message; } public String toString() { return message; } }
//主类,管理系统类 public class CarRentslSystem { public static void main(String[] args) throws aException{ Admin admin = new Admin(); VIPUser vipUser = new VIPUser(admin.getVehicles()); Scanner scanner = new Scanner(System.in); while (true) { System.out.println("欢迎来到星河灿烂汽车租赁系统!"); System.out.println("请选择用户类型(1. 管理员,2. VIP用户,3. 退出):"); int choice = scanner.nextInt(); switch (choice) { case 1: adminMenu(admin); break; case 2: vipUserMenu(vipUser); break; case 3: System.out.println("已退出系统!"); System.exit(0); default: try { throw new aException("无效的选择!"); } catch(aException e) { System.out.println("无效的选择!"); } } } } // 管理员菜单 private static void adminMenu(Admin admin) throws aException{ Scanner in = new Scanner(System.in); System.out.print("请输入用户名:"); String username = in.nextLine(); System.out.print("请输入密码:"); String password = in.nextLine(); if (username.equals("admin123") && password.equals("admin123")) { System.out.println("管理员登录成功!"); } else { System.out.println("登录失败,请重新登录"); return; } Scanner scanner = new Scanner(System.in); while (true) { System.out.println("请选择操作(1. 查看车辆信息,2. 添加车辆,3. 修改车辆信息,4. 删除车辆,5. 查看营业额,6. 退出):"); int choice = scanner.nextInt(); switch (choice) { case 1: admin.viewVehicles(); break; case 2: admin.addVehicle(); break; case 3: admin.editVehicle(); break; case 4: admin.deleteVehicle(); break; case 5: admin.viewRevenue(); break; case 6: return; default: try { throw new aException("无效的选择!"); } catch(aException e) { System.out.println("无效的选择!"); } } } } // VIP用户菜单 private static void vipUserMenu(VIPUser vipUser) throws aException{ VIPUser.set=0; Scanner in = new Scanner(System.in); System.out.print("请输入用户名:"); String username = in.nextLine(); System.out.print("请输入密码:"); String password = in.nextLine(); if ((username.equals("张三") && password.equals("sd4578hg"))||(username.equals("李四") && password.equals("1265dfsa") )||(username.equals("王五") && password.equals("378627as"))){ System.out.println("VIP用户登录成功!"); } else { System.out.println("登录失败!请检查用户名及密码,或者你不是VIP用户。"); System.out.println("是否注册VIP用户?1.是 2.否"); int de=in.nextInt(); if(de==1) { System.out.println("请输入你的用户名:"); String username1 = in.nextLine(); String s = in.nextLine(); System.out.println("请输入你的密码:"); String password1 = in.nextLine(); System.out.println("注册成功,已成功登录!"); } else if(de==2) { return; } } Scanner scanner = new Scanner(System.in); while (true) { System.out.println("请选择操作(1. 查看可租车辆,2. 租车,3. 换车,4.模拟付款,5. 退出):"); int choice = scanner.nextInt(); switch (choice) { case 1: vipUser.viewAvailableVehicles(); break; case 2: vipUser.rentVehicle(); break; case 3: vipUser.changeVehicle(); break; case 4: vipUser.makePayment(); break; case 5: return; default: try { throw new aException("无效的选择!"); } catch(aException e) { System.out.println("无效的选择!"); } } } } }