首页 > 编程语言 >编程打卡:面向对象程序设计

编程打卡:面向对象程序设计

时间:2023-05-24 19:34:21浏览次数:36  
标签:String 编程 System name 面向对象 println 打卡 staff out

import java.util.*;

public class StaffManagementSystem {

    private static List<Staff> staffList = new ArrayList<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("Welcome to the Staff Management System. What would you like to do?");
            System.out.println("1. Add a staff member");
            System.out.println("2. Remove a staff member");
            System.out.println("3. List all staff members");
            System.out.println("4. Quit");

            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    addStaffMember(scanner);
                    break;
                case 2:
                    removeStaffMember(scanner);
                    break;
                case 3:
                    listAllStaffMembers();
                    break;
                case 4:
                    System.out.println("Goodbye!");
                    System.exit(0);
            }
        }
    }

    private static void addStaffMember(Scanner scanner) {
        System.out.println("Enter the staff member's name:");
        String name = scanner.nextLine();

        System.out.println("Enter the staff member's department:");
        String department = scanner.nextLine();

        System.out.println("Enter the staff member's job title:");
        String jobTitle = scanner.nextLine();

        staffList.add(new Staff(name, department, jobTitle));
        System.out.println("Staff member added successfully!");
    }

    private static void removeStaffMember(Scanner scanner) {
        System.out.println("Enter the staff member's name:");
        String name = scanner.nextLine();

        Staff staffToRemove = null;
        for (Staff staff : staffList) {
            if (staff.getName().equals(name)) {
                staffToRemove = staff;
            }
        }

        if (staffToRemove == null) {
            System.out.println("Staff member not found!");
        } else {
            staffList.remove(staffToRemove);
            System.out.println("Staff member removed successfully!");
        }
    }

    private static void listAllStaffMembers() {
        for (Staff staff : staffList) {
            System.out.println(staff);
        }
    }
}

class Staff {

    private String name;
    private String department;
    private String jobTitle;

    public Staff(String name, String department, String jobTitle) {
        this.name = name;
        this.department = department;
        this.jobTitle = jobTitle;
    }

    @Override
    public String toString() {
        return "Staff{" +
                "name='" + name + '\'' +
                ", department='" + department + '\'' +
                ", jobTitle='" + jobTitle + '\'' +
                '}';
    }
}

标签:String,编程,System,name,面向对象,println,打卡,staff,out
From: https://www.cnblogs.com/sugar-refinery/p/17429295.html

相关文章

  • 5.24打卡
    #include<bits/stdc++.h>usingnamespacestd;classPoint{public:Point(intxx=0,intyy=0){x=xx;y=yy;}Point(Point&p);intgetX(){returnx;......
  • 5.24打卡
     3.程序流程图 4.代码实现#include<bits/stdc++.h>usingnamespacestd;main(){intx,y,z,num=0;printf("MenWomenChildren\n");for(x=0;x<=10;x++){y=20-2*x;z=30-x-y;if(3*x+2*y+z==50)......
  • 【编程日记】搭建python开发环境
    0.相关确定0.1确定操作系统Python是一种跨平台的编程语言,这意味着它能够运行在所有主要的操作系统中。然而,在不同的操作系统(Windows/Mac/Linux)中,安装Python的方法存在细微的差别。本教程我们使用的是Windows系统,对于Mac和Linux暂时不做介绍0.2确定Python版本当前有两个不同的......
  • 每日打卡1057
    给定一串长度不超过 105 的字符串,本题要求你将其中所有英文字母的序号(字母a-z对应序号1-26,不分大小写)相加,得到整数N,然后再分析一下N的二进制表示中有多少0、多少1。例如给定字符串 PAT(Basic),其字母序号之和为:16+1+20+2+1+19+9+3=71,而71的二进制是1000111,即有3个......
  • Ruby教程_编程入门自学教程_菜鸟教程-免费教程分享
    教程简介Ruby,一种简单快捷的面向对象(面向对象程序设计)脚本语言,在20世纪90年代由日本人松本行弘(YukihiroMatsumoto)开发,遵守GPL协议和RubyLicense。它的灵感与特性来自于Perl、Smalltalk、Eiffel、Ada以及Lisp语言。由Ruby语言本身还发展出了JRuby(Java平台)、IronRuby(.NET......
  • 编程感悟 —— 底层知识与实际运用的结合
    对于编程的理解往往是对底层原理和进阶知识的融合。例如Map和List在SpringBoot框架下进行业务操作时,其底层的存储和实现往往会用到这些基础知识,甚至包括了线程池和内存原理。这就是编程思想中的一部分最底层的极具魅力的过程!......
  • 5_24_打卡_数据结构之循环队列
    //循环队列可存储数据数量是maxsize-1//队列长度为(front-rear+maxsize)%maxsize//队列为空时front==rear//队列满时(front+1)%maxsize==rear;#defineMAXSIZE5#include<iostream>usingnamespacestd;typedefstructqueue{ intfront; intrear; intdata[MAXSIZE];}......
  • 全网最全的编程电子书大合集,超千本打包下载
    分享计算机电子书,覆盖了Java、C、Python、Go等多种编程语言,更有算法、基础组件、框架、计算机基础等丰富多样的电子书。目前收录了1000+本免费分享,本栏目已被1w+个用户关注,希望我们整理的资源能够为程序员提供到学习帮助。想要一次性保存全部电子书的小伙伴可以如下操作,看到后......
  • < Python全景系列-6 > 掌握Python面向对象编程的关键:深度探索类与对象
    欢迎来到我们的系列博客《Python全景系列》!在这个系列中,我们将带领你从Python的基础知识开始,一步步深入到高级话题,帮助你掌握这门强大而灵活的编程语法。无论你是编程新手,还是有一定基础的开发者,这个系列都将提供你需要的知识和技能。Python全景系列的第六篇,本文将深入探讨Python......
  • 实验4 函数与异常处理编程
    实验任务一task1:程序源代码:1print(sum)2sum=423print(sum)45definc(n):6sum=n+17print(sum)8returnsum910sum=inc(7)+inc(7)11print(sum)运行结果:实验任务二task2-1源代码:1deffunc1(a,b,c,d,e,f):2......