第9章 Java异常处理

40 篇文章 0 订阅
40 篇文章 0 订阅

13、完整的视图类TeamView

package com.atguigu.view;

 

import com.atguigu.bean.Architect;

import com.atguigu.bean.Designer;

import com.atguigu.bean.Employee;

import com.atguigu.bean.Programmer;

import com.atguigu.service.NameListService;

import com.atguigu.service.TeamException;

import com.atguigu.service.TeamService;

import com.atguigu.util.TSUtility;

 

public class TeamView {

    private NameListService listSvc = new NameListService();

    private TeamService teamSvc = new TeamService();

 

    public void enterMainMenu() {

        boolean loopFlag = true;

        char key = 0;

 

        do {

            if (key != '1') listAllEmployees();

            System.out.print("1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):");

            key = TSUtility.readMenuSelection();

            System.out.println();

            switch (key) {

                case '1':

                    listTeam();

                    break;

                case '2':

                    addMember();

                    break;

                case '3':

                    deleteMember();

                    break;

                case '4':

                    System.out.print("确认是否退出(Y/N):");

                    char yn = TSUtility.readConfirmSelection();

                    if (yn == 'Y') loopFlag = false;

                    break;

            }

        } while (loopFlag);

    }

 

    private void listAllEmployees() {

        System.out.println("\n-------------------------------开发团队调度软件--------------------------------\n");

        Employee[] emps = listSvc.getAllEmployees();

        if (emps.length == 0) {

            System.out.println("没有客户记录!");

        } else {

            System.out.println("ID\t姓名\t年龄\t工资\t职位\t状态\t奖金\t股票\t领用设备");

        }

 

        for (Employee e : emps) {

            System.out.println(" " + e);

        }

        System.out.println("-------------------------------------------------------------------------------");

    }

 

    private void listTeam() {

        System.out.println("\n--------------------团队成员列表---------------------\n");

        Programmer[] team = teamSvc.getTeam();

        if (team.length == 0) {

            System.out.println("开发团队目前没有成员!");

        } else {

            System.out.println("TDI/ID\t姓名\t年龄\t工资\t职位\t奖金\t股票");

        }

 

        for (Programmer p : team) {

             if (p instanceof Architect) {

                 Architect a = (Architect) p;

                 System.out.println(" " + a.getMemberId() + "/" + a.getDetails() + "\t架构师\t"a.getBonus() + "\t" + a.getStock());

             } else if (p instanceof Designer) {

                 Designer d = (Designer) p;

                 System.out.println(" " + d.getMemberId() + "/" + d.getDetails() + "\t设计师\t" + d.getBonus());

             } else if (p instanceof Programmer) {

                 System.out.println(" " + p.getMemberId() + "/" + p.getDetails() + "\t程序员");

             }

           

        }

        System.out.println("-----------------------------------------------------");

    }

 

    private void addMember() {

        System.out.println("---------------------添加成员---------------------");

        System.out.print("请输入要添加的员工ID:");

        int id = TSUtility.readInt();

 

        try {

            Employee e = listSvc.getEmployee(id);

            teamSvc.addMember(e);

            System.out.println("添加成功");

        } catch (TeamException e) {

            System.out.println("添加失败,原因:" + e.getMessage());

        }

       

        TSUtility.readReturn();//回车继续

    }

 

    private void deleteMember() {

        System.out.println("---------------------删除成员---------------------");

        System.out.print("请输入要删除员工的TID:");

        int id = TSUtility.readInt();

        System.out.print("确认是否删除(Y/N):");

        char yn = TSUtility.readConfirmSelection();

        if (yn == 'N') return;

 

        try {

            teamSvc.removeMember(id);

            System.out.println("删除成功");

        } catch (TeamException e) {

            System.out.println("删除失败,原因:" + e.getMessage());

        }

 

        TSUtility.readReturn();//回车继续

    }

 

    public static void main(String[] args) {

        T

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值