里面有 父类 子类 接口 以及 各种循环和键盘录入...实现了员工的增删改查 抽取幸运员工 以及 客人的Vip服务
[Java] 纯文本查看 复制代码
import java.util.*;
public class HotelManageSystem {
public static void main(String[] args) {
Manager m = new Manager("严伟","经理001");
Cooker c = new Cooker("朱闯", "厨师001");
Waiter w1 = new Waiter("张三", "服务员001");
Waiter w2 = new Waiter("李四", "服务员002");
ArrayList<Employee> al = new ArrayList<Employee>();
al.add(m);
al.add(c);
al.add(w1);
al.add(w2);
while(true){
System.out.println("========黑马大酒店管理系统=======");
System.out.println("1.员工管理界面...");
System.out.println("2.幸运员工随机...");
System.out.println("3.酒店Vip服务...");
System.out.println("4.退出系统...");
int num = choice();
if(num==1){
manageEmployeeSystem(al);
}else if(num==2){
Employee e = rdLuck(al);
System.out.println("幸运员工是...."+e.getName()+"....编号是: "+e.getId());
}else if(num==3){
vip(al);
}else if(num==4){
System.out.println("谢谢使用本系统");
return;
}
}
}
//人员管理系统
public static void manageEmployeeSystem(ArrayList<Employee> al){
while(true){
System.out.println("========酒店人员管理界面=======");
System.out.println("1.添加员工");
System.out.println("2.删除员工");
System.out.println("3.查询员工");
System.out.println("4.修改员工");
System.out.println("5.返回");
int num = choice();
if(num==1){
addEmployeeSystem(al);
}else if(num==2){
delEmployeeSystem(al);
}else if(num==3){
searchEmployeeSystem(al);
}else if(num==4){
replaceEmployeeSystem(al);
}else if(num==5){
return;
}else{
System.out.println("输入错误请重新输入");
}
}
}
//选择需要修改的内容
public static void replaceEmployee(int i,ArrayList<Employee> al){
int num =0;
System.out.println("========修改员工职位界面=======");
System.out.println("1.经理");
System.out.println("2.厨师");
System.out.println("3.服务员");
System.out.println("4.返回");
num = choice();
if(num==1){
setEmployee(i,al,new Manager());
}else if(num==2){
setEmployee(i,al,new Cooker());
}else if(num==3){
setEmployee(i,al,new Waiter());
}else if(num==4){
return;
}else{
System.out.println("输入错误请重新输入");
}
}
//修改员工职位
public static void setEmployee(int num,ArrayList<Employee> al,Employee e){
Scanner sc = new Scanner(System.in);
System.out.println("请输入姓名");
e.setName(sc.next());
System.out.println("请输入编号");
e.setId(sc.next());
if(e instanceof Manager){
System.out.println("请输入需要修改的经理奖金");
((Manager) e).setBonus(sc.nextInt());
}
al.set(num,e);
}
//修改员工
private static void replaceEmployeeSystem(ArrayList<Employee> al) {
while(true){
System.out.println("========修改员工界面=======");
System.out.println("1.修改员工");
System.out.println("2.返回");
int num=choice();
if(num==1){
System.out.println("请输入需要修改的员工编号:");
String id = new Scanner(System.in).next();
for(int i=0;i<al.size();i++){
if(al.get(i).getId().equals(id)){
System.out.println("需要修改的员工:");
System.out.println(al.get(i).getName()+".."+al.get(i).getId());
replaceEmployee(i,al);
break;
}else if(i==al.size()-1){
System.out.println("没有该编号,查找错误!");
}
}
}else if(num==2){
return;
}else{
System.out.println("输入错误!");
}
}
}
//查找员工
public static void searchEmployeeSystem(ArrayList<Employee> al){
while(true){
System.out.println("========查找员工界面=======");
System.out.println("1.查找员工");
System.out.println("2.打印员工清单");
System.out.println("3.返回");
int num=choice();
if(num==1){
System.out.println("输入需要查找的员工的编号");
String id = new Scanner(System.in).next();
for(int i=0;i<al.size();i++){
if(al.get(i).getId().equals(id)){
System.out.println("查找到的员工:");
System.out.println(al.get(i).getName()+".."+al.get(i).getId());
al.get(i).work();
if(al.get(i) instanceof Manager){
System.out.println("经理奖金为:"+((Manager)al.get(i)).getBonus());
}
break;
}else if(i==al.size()-1){
System.out.println("没有该编号,查找错误!");
}
}
}else if(num==2){
sprintEmployee(al);
}else if(num==3){
return;
}else{
System.out.println("输入错误!");
}
}
}
//删除员工
public static void delEmployeeSystem(ArrayList<Employee> al){
while(true){
System.out.println("========删除员工界面=======");
System.out.println("1.删除员工");
System.out.println("2.返回");
int num=choice();
if(num==1){
System.out.println("请输入要删除的员工编号");
String id = new Scanner(System.in).next();
for(int i=0;i<al.size();i++){
if(al.get(i).getId().equals(id)){
System.out.println("您已删除"+al.get(i).getName()+".."+al.get(i).getId());
al.remove(i);
System.out.println("删除成功!");
break;
}else if(i==al.size()-1){
System.out.println("没有该编号,删除错误!");
}
}
}else if(num==2){
return;
}else{
System.out.println("输入错误!");
}
}
}
//添加员工界面
public static void addEmployeeSystem(ArrayList<Employee> al){
int num =0;
System.out.println("========添加员工界面=======");
System.out.println("1.添加经理");
System.out.println("2.添加厨师");
System.out.println("3.添加服务员");
System.out.println("4.返回");
num = choice();
if(num==1){
addEmployee(al,new Manager());
}else if(num==2){
addEmployee(al,new Cooker());
}else if(num==3){
addEmployee(al,new Waiter());
}else if(num==4){
return;
}else{
System.out.println("输入错误请重新输入");
}
}
//添加员工
public static void addEmployee(ArrayList<Employee> al,Employee e){
Scanner sc = new Scanner(System.in);
System.out.println("请输入姓名");
e.setName(sc.next());
System.out.println("请输入编号");
e.setId(sc.next());
if(e instanceof Manager){
System.out.println("请输入经理的奖金");
((Manager) e).setBonus(sc.nextInt());
}
al.add(e);
}
//vip 服务
public static void vip(ArrayList<Employee> al){
int num=0;
while(true){
System.out.println("你是否需要Vip服务");
System.out.println("1.需要.....2.不需要");
num=choice();
if(num==1){
for(int i=0;i<al.size();i++){
if(al.get(i) instanceof Cooker){
((Cooker)al.get(i)).vip();
}else if(al.get(i) instanceof Waiter){
((Waiter)al.get(i)).vip();
}
}
return;
}else if(num==2){
return;
}else{
System.out.println("输入错误请重新输入");
}
}
}
//员工清单打印
public static void sprintEmployee(ArrayList<Employee> al){
System.out.println("姓名.............编号");
for(int i=0;i<al.size();i++){
System.out.println(al.get(i).getName()+"............."+al.get(i).getId());
}
}
//选择器
public static int choice(){
return (new Scanner(System.in).nextInt());
}
//幸运员工获取器
public static Employee rdLuck(ArrayList<Employee> al){
return al.get(new Random().nextInt(al.size()));
}
}
public class Cooker extends Employee implements Vip{
public Cooker(){
}
public Cooker(String name, String id) {
super(name, id);
}
public void work(){
System.out.println("职位:厨师.......做饭");
}
public void vip() {
System.out.println(this.getName()+" "+this.getId()+"厨师给客人的菜加量...");
}
}
/*
* 经理 厨师 服务员
* */
public abstract class Employee {
private String name;
private String id;
public Employee(){
}
public Employee(String name,String id){
this.setName(name);
this.setId(id);
}
public abstract void work();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
public class Manager extends Employee{
private int bonus=5000;
public Manager(){
}
public Manager(String name, String id) {
super(name, id);
}
public void work() {
System.out.println("职位:经理.......管理饭店");
}
public int getBonus() {
return bonus;
}
public void setBonus(int bonus) {
this.bonus = bonus;
}
}
public interface Vip {
void vip();
}
public class Waiter extends Employee implements Vip{
public Waiter(){
}
public Waiter(String name, String id) {
super(name, id);
}
public void work() {
System.out.println("职位:服务员.......服务客人");
}
public void vip() {
System.out.println(this.getName()+" "+this.getId()+"服务员给客人倒酒..");
}
}
也没时间再细化了,就先这样吧......
|