java--汽车租赁系统最后一天完成主类和异常类

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("无效的选择!");
                    }
            }
        }
    }
}
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值