在控制台应用程序中为同一类创建不同的对象? [英] create different objects for same class in console application??

查看:56
本文介绍了在控制台应用程序中为同一类创建不同的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个菜单驱动的控制台应用程序
1.员工详细信息
2.删除员工
3.编辑员工

要在我的应用程序中添加1个以上的雇员,我每次都必须创建同一雇员类的不同对象吗?

我无法弄清楚当用户选择第二个选项时如何删除员工,甚至如何编辑员工?任何建议?

i created a menu driven console application
1. employee details
2. delete employee
3. edit employee

to add more then 1 employee in my application do i have to create different objects of the same employee class every time??

i cant figure out how to delete the employee when user goes for the 2nd option and even how to edit the employee?? any suggestions??

推荐答案

现在,这取决于您如何创建员工类.如果您为用户的名字,姓氏等使用了单独的字符串,则必须创建不同的对象.如果您在类中使用了某种arraylist或堆类型的机制,则可以添加多个雇员.

要委派emplyee,您可以显示员工列表并要求输入一些ID,将ID存储在数组中,然后相应地调用delete方法.

对于更新,如果要进行批量更新,则需要完成一些繁琐的工作

因此,请先执行此操作,然后如果发生某些错误,则可以再次将其发布在这里...

快乐的编码...
Now it depends on how you have created your employee class. if you have used separate strings for user''s firstname, lastname, etc. then you have to create different objects. if you have used some arraylist or heap kind of mechanism in the class then you can add more than one employee.

for deleing emplyee you can show list of employees and ask to enter some id ,store the ids in array and then call the delete method accordingly.

and for update it is some tedious work to do if you want to do bulk updates

so, do it first, then if some error occurred you can post it here again...

happy coding...


OOPS的思想是为一个类具有不同的对象.

您可能需要使用ID或集合或其他内容来跟踪这些对象.完成后,删除和编辑应该很容易.
The idea behind OOPS is to have different objects for one class.

You might need to track these objects using an Id or a collection or something. Once that is done, deleting and editing should be easy.


这篇关于在控制台应用程序中为同一类创建不同的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆