LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   We are given the following tasks and I wonder how to do this... (https://www.linuxquestions.org/questions/linux-newbie-8/we-are-given-the-following-tasks-and-i-wonder-how-to-do-this-762079/)

colan1838 10-15-2009 07:51 AM

We are given the following tasks and I wonder how to do this...
 
TASK A:
After review with management, it is decided that we will store the following information for each employee:
• employee ID (an integral number, automatically assigned when a new employee is added)
• first name and last name
• department number (an integral value, call it dept)
• pay rate (a floating-point value, using a double)
In addition, we would like:
• a method called getPayInfo() that will return a sentence with the employee's name, id, department, and check amount
• a method called getFullName() that will return the first and last names separated by a space
1. Define a class called Employee with these characteristics, using standard practices for limiting data access and for method naming
2. In order to be useful, there should be methods to set and get all properties (except setting the employee id, which will happen automatically in a manner to be determined later; for now, just let it default to 0)
3. Create a class called Payroll with a main method, it should:
o instantiate an Employee object
o set values for all properties
o call the getPayInfo() method to see the results
TASK B:
1. Modify your Employee class to use a constructor that accepts parameters for the first and last names, department, and pay rate
2. In Payroll, modify main to add another Employee variable that receives an instance created using this constructor
3. Also add a constructor that takes no parameters and does nothing (as we discussed above)
public Employee() { }

TASK C:
1. Add more Employee constructors:
o one that takes values for first and last names only
o one that takes values for first name, last name, and department
o one that takes values for first name, last name, and pay rate
o note that, in practice, you can use the parameter lists for constructors to help enforce what you would consider valid combinations of properties - for example, if you would not want an employee to exist in a state where they had name and department information, but no pay rate, then the absence of that particular constructor would help ensure that
o judicious use of copy-paste-edit can speed up this process, but be careful to make every necessary edit if you do this!
2. Create and pay additional instances using these constructors
3. You will find yourself writing somewhat repetitive code, setting the same values the same way in several different constructors - we will address this in a few pages
TASK D:
1. Now we can clean up our Employee class definition
2. Modify the set methods to use the same name for each parameter as the associated property
3. Modify the constructors to eliminate redundant code - for example:
public Employee(String firstName, String lastName, int dept) {
this(firstName, lastName);
setDept(dept);
}

TASK E:
1. Add a private and static integer property called nextId to the Employee class (give it an initial value of 1)
2. Modify the declaration of the id property as follows:
private int id = nextId++;
3. What happens when each new Employee gets instantiated?
TASK F:
1. Create a package called employees; put the Employee class into this package (leave Payroll where it is)
2. This will require not only creating the directory and moving the file, but also adding an import statement to Payroll and a package statement to Employee
3. To compile, start in the project root directory (the directory containing Payroll). If you compile Payroll as usual, it will also find and compile Employee. To compile just Employee, you would still work in the project root directory, but execute
javac employees\Employee.java
4. Run Payroll in the usual fashion


I have already working with this but i can't finish it in my own...

threelions66 10-15-2009 08:15 AM

Re:
 
If I were you I'd post this question on http://www.codeproject.com/
That's the crowd you want to talk to

Lordandmaker 10-15-2009 08:19 AM

I don't think I've ever seen such a blatant "Do my homework for me" post.

colan1838 10-15-2009 08:56 AM

sorry,,
 
Quote:

Originally Posted by Lordandmaker (Post 3720262)
I don't think I've ever seen such a blatant "Do my homework for me" post.

But I really need help regarding with this matter. Infact while i'm waiting for any reply I am also doing the tasks. Yet i'mnot still finish.

Wim Sturkenboom 10-15-2009 09:02 AM

Quote:

Originally Posted by colan1838 (Post 3720228)
...

I have already working with this but i can't finish it in my own...

OK, so tell us with what you're stuck and show us the code that you've written till now.

PS
1)
I've once helped somebody with his homework and as a result he failed because the code that he handed in was too advanced for the level.
2)
There is a programming section here at LQ

pixellany 10-15-2009 09:08 AM

Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

In other words, show us your work and ask specific questions.

TB0ne 10-15-2009 09:39 AM

Quote:

Originally Posted by colan1838 (Post 3720299)
But I really need help regarding with this matter. Infact while i'm waiting for any reply I am also doing the tasks. Yet i'mnot still finish.

Well if this is homework, and you say you're working on it, post what you've written and where you're having a problem, and we'll be glad to help you.

If this is for you at your place of employment, you're getting paid to do this work. If you "really need help", again, POST WHAT YOU'VE WRITTEN and we can help you. Otherwise, do the job you were hired to do, or tell your boss you're in over your head.

johnsfine 10-15-2009 11:51 AM

Quote:

Originally Posted by TB0ne (Post 3720334)
If this is for you at your place of employment

Don't be absurd.

It is from this online Java lesson
http://www.learn-java-tutorial.com/J...jects.cfm#h1.3

I don't care to guess whether the OP is using that lesson directly or whether his instructor either copied from there or maybe is the original author of the lesson and using it in more than one place.

Quote:

Originally Posted by colan1838 (Post 3720228)
I have already working with this but i can't finish it in my own...

If you are learning Java in a classroom and didn't have the above link to the online version, you apparently missed some things in class (or you would be able to do this easy assignment). Try reading the online version of the lesson to fill in the gaps for whatever you missed in class.

If you were already using that online lesson, tell us which specific details you don't understand.

pixellany 10-15-2009 12:58 PM

Everyone Chill!! .....:)
If this follows the typical homework pattern, OP is not listening and will not be back.

A WEE bit off-topic: I would love to find a fair and yet effective to curtail the more egregious homework posts---the ideas should go in LQ suggestions and feedback

catkin 10-15-2009 01:06 PM

Quote:

Originally Posted by pixellany (Post 3720578)
Everyone Chill!! .....:)
If this follows the typical homework pattern, OP is not listening and will not be back.

A WEE bit off-topic: I would love to find a fair and yet effective to curtail the more egregious homework posts---the ideas should go in LQ suggestions and feedback

OK -- chilled! :hattip:

Thanks for "egregious" -- le bon mot and appositely applied! :)

pixellany 10-15-2009 01:21 PM

And thank YOU for "appositely".....:)

And now we will close this masterpiece----colan1838 is invited to start a new thread which follows the homework guidelines so eloquently and appositely elucidated herein......:)


All times are GMT -5. The time now is 10:42 PM.