We are given the following tasks and I wonder how to do this...
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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...
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
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.
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.
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
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.
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
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!
Thanks for "egregious" -- le bon mot and appositely applied!
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......
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.