• Post Reply Bookmark Topic Watch Topic
  • New Topic

Employee Database program  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am a first year CS student and I'm having trouble coding the rest of this project and I was wondering if anyone could offer some help, if so I'd be happy to provide the instructions and all of the code that I have so far.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Ace wrote:if so I'd be happy to provide the instructions and all of the code that I have so far.

So, go ahead, and we'll do our best.

However: If there's a lot of code, we don't want it all; so be selective. Have a look at the HowToAskQuestionsOnJavaRanch (←click) page for information.

Winston
 
Jack Ace
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, thanks. Here are the instructions and It seems like I've completed about 80% of the program itself I just can't seem to finish the last few points.

Your program must be designed using the following class.
Database class
Instance variables
• Static int[] empNumber;
• Static string[] empName;
• Static String[] empAddress;
• Static int[] empSalary;
• Static Scanner scan = new Scanner(systemin);
• Static int maxEmployees;
Public static void main(String args[])
• Prompts the user for the maximum number of employees to store. Save this value in a variable called numOfEmployees
• Instantiates a new Database class
• Invokes the menu method and passes the number of employees value
Public void menu(int numOfEmployees)
• maxEmployees = numOfEmployees;
• initializes the 4 instance arrays with the size = maxEmployees

empNumber = new int [maxEmployees];
empName = new string [maxEmployees];
empAddress = new string [maxEmployees];
empSalary = new int[maxEmployees];
• prints out the control menu, which looks like the following:
Employee Management System Menu
a) Add a new Employee
b) Delete an Employee
c) Print the Employee List
d) Print a Specific Employee
e) Exit the Employee Management System
Each of the first four options will invoke a method to perform the required operation. The final option will exit the menu loop and end the application.
Public void addEmployee()
• Walks through the empNumber array looking for the next free cell; when it finds it, prompts the user for the four parameters required to add a new employee; it then walks through the empNumber array looking to see if the employee number already exist; if it does not, then it adds all 4 values provided by the user to the corresponding arrays.
Public void printEmployeeList()
• Walks through all the arrays looking for employee entries and prints them out.
Public void printEmployee(int empID)
• Walks through the empNumber array looking for the matching empID; when it finds it, it prints out the matching entry from all the arrays.
Public void deleteEmployee(int empID)
• Walks through the empNumber array looking for the matching empID; when it finds it, it sets all the array cells equal




I apologize if this is too much and appreciate any sort of feedback. This is supposed to be done by the 13th of December so I have some time left, but I'd like to finish as soon as possible.
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK so what bit do you need help with?
Does the code you have so far compile and work as intended?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Ace wrote:Here are the instructions and It seems like I've completed about 80% of the program itself I just can't seem to finish the last few points.
Your program must be designed using the following class.
Database class
Instance variables
• Static int[] empNumber;
...

Well, I hate to say, but that looks wrong right there. An "instance" variable doesn't have the static qualifier.

Also, the whole design looks awful - mainly because there's no 'Employee' class - but if that's what they told you to do, then I guess you should follow their instructions. It's possible that they just want to teach you about arrays right now.

I'm also a little puzzled by the deleteEmployee() method. What exactly do they want you to do? The instructions as you've posted them seem to be incomplete.

Also: the instructions seem to be incredibly detailed. Are you allowed to add any other methods and/or variables of your own? That's certainly what I'd want to do.

Specifically: Most "collections" like this have two variables related to size:
  • Capacity: the maximum number of items your collection can hold (ie, your maxEmployees field).
  • Current size: The number of items that are currently stored in the collection. This variable is usually updated when you add or remove something.

  • That allows you to easily check if your "database" is full, viz:
    Finally (and again, if you're allowed to): Try and remove as much code as you possibly can from your main() method.
    For example: if you had a method like:you could remove all that code from main().
    And if you had another one like:your while loop now becomes:Do you see how much easier that is to read?

    HIH

    Winston
     
    Sheriff
    Posts: 11495
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote:It's possible that they just want to teach you about arrays right now.

    And that's my point again. There are much better, more focused ways to teach kids about arrays. Putting it in the context of a bad design will take away from the kids' learning experience. If that's the case here, I think the bad design actually distracts the kids. Context is a big part of learning how to program. Using something out of the context for which it is appropriate is the exact definition of an Anti-Pattern. At worst, they're teaching kids how to write programs with Anti-Patterns.
     
    Junilu Lacar
    Sheriff
    Posts: 11495
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote:
    Well, I hate to say, but that looks wrong right there. An "instance" variable doesn't have the static qualifier.

    Also, the whole design looks awful - mainly because there's no 'Employee' class - but if that's what they told you to do, then I guess you should follow their instructions. It's possible that they just want to teach you about arrays right now.

    [I think I forgot to post this before I posted the intended follow-up above that starts with "And that's my point again"]

    This is what I find disappointing about how it seems kids are being taught in school, even in this day and age. None of this prepares them for working in the real world. In fact, it shows them antiquated ways of developing applications and deprives them of the chance to learn how to work with others and come up with designs that are well-factored and maintainable. It seems these instructors have no idea of what's going on in the real world and base their lesson plans on SDLCs from the 1990s.
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Junilu Lacar wrote:Putting it in the context of a bad design will take away from the kids' learning experience...

    The only thing I can think of is that it's some sort of "aversion therapy", as practised in some apprenticeship programs:

    Learn how to do it the wrong way (even if it seems right); then, when you learn how to do it properly, and work out how much easier it makes everything, you remember it better.

    Just a guess.

    Winston
     
    Junilu Lacar
    Sheriff
    Posts: 11495
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote:The only thing I can think of is that it's some sort of "aversion therapy", as practised in some apprenticeship programs:

    Learn how to do it the wrong way (even if it seems right); then, when you learn how to do it properly, and work out how much easier it makes everything, you remember it better.

    Maybe I'm just a cynic but it doesn't seem that way from the instructions given and from what the OP has posted so far. I doubt the instructor even has refactoring in the lesson plan. And again, if for some reason what you say is true, there are better ways to do that than this, IMO. I have taught professionals about code anti-patterns and refactoring with 20 lines of code (see Compose Method) and a guided group code review.
     
    Junilu Lacar
    Sheriff
    Posts: 11495
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Refactoring to put things in better places:

    Refactoring main loop:

    See how a Composed Method that adheres to the Single Level of Abstraction Principle makes it even better?

    [Edit: fixed bug: call printSelectionMenu() instead of printEmployeeMenu() -- could probably find a better name than these. And I guess since everything else is static, promptForAction should also be static ]
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Junilu Lacar wrote:Maybe I'm just a cynic but it doesn't seem that way from the instructions given and from what the OP has posted so far...

    Possibly, but I reckon there's a second problem of "introducing too much too soon". Java syntax is tough enough without trying to pile on all sorts of "objective" stuff right at the start; and the fact is that Java IS a hybrid language.

    If you want kids to learn objects right from the outset, give 'em a language like Smalltalk; not one that requires you to run a procedural method right from the outset. And TBH, I'm not sure I'd want to learn Smalltalk as my first language.

    @Jack: Apologies for this diversion (and indeed, for the reference to 'kids'). It's just what we contributors get up to in the absence of input.

    Winston
     
    Junilu Lacar
    Sheriff
    Posts: 11495
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote:Possibly, but I reckon there's a second problem of "introducing too much too soon". Java syntax is tough enough without trying to pile on all sorts of "objective" stuff right at the start;

    Which is why I think smaller, more focused examples that cater to one or two objectives are a better way. The problem given needs the solver to already know how to "walk" an array to some extent. If "walking" an array is the learning objective then give them a simple linear search problem.

    If the learning objective is to teach them how to organize data into logical entities and introduce object-orientation, then give them proper objects, not these disjoint data structures reminiscent of structured/procedural programming techniques.

    Apologies for ... (and indeed, for the reference to 'kids').

    Sorry if "kids" is non-PC. I'm just showing my age in thinking that anybody who's still in school is just a "kid." My reference phrase is "script kiddies". Should I use another word? "Young people" is kind of a mouthful.
     
    Junilu Lacar
    Sheriff
    Posts: 11495
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Jack Ace wrote:okay, thanks. Here are the instructions and It seems like I've completed about 80% of the program itself I just can't seem to finish the last few points.


    Coming back to your immediate problem... exactly which last few points are you unable to finish?
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!