Stan Austin wrote: it must not be edited
Create your own program called Manage; Manage will have 4 functions
1. change the employees income by applying a bonus or penalty.
2. take an array, of employees returning a boolean if two names match
3. return the total sum of all salaries in an array
4. print the name which is first alphabetically
Campbell Ritchie wrote:Good grief! What poorly‑formatted code. What bad method names! Did you really copy that code without changes? You will have to create a method to increase the salary and put it in a class called Manage (a poor name for a class, by the way). Once you have done that, consider the rest of the assignment.
Paul Clements wrote:Stan, keep it simple. One step at a time i.e.
...
Build slowly on something which works. Don't get lost thinking too far ahead.
Stan Austin wrote:however if i try to print "Employee.salary" it tells me salary is private!
Paul Clements wrote:
Stan Austin wrote:however if i try to print "Employee.salary" it tells me salary is private!
Yes. That's called "encapsulation". It means keeping instance variable private and only allowing manipulation though the classes own methods i.e. what are commonly known as setters and getters. The getter on 'Salary' is salary(). Therefore if from within manage. java you create an Employee instance called e1 then e1.salary() should return what's held in 'Salary'.
You have mentioned it twice. That is a bad name for a class source file. Campbell told that already. Another thing is, that it should start with an upper case - very important to avoid further mess (a bit too late, probably OP will need to press and hold CTRL then A and most likely DEL).Paul Clements wrote:Create manage.java
Stan Austin wrote:Sorry im not sure i get this, been toying with it for the last 10 mins and I'm getting nothing
1000
1010
990
Paul Clements wrote:
Do you understand this code and output?
Campbell Ritchie wrote: I think that suggestion will do what is required of you. Why not post the code as it really should be, rather than messing up the method names?
Campbell Ritchie wrote:What is wrong with line 33? It looks all right to me. I suggest you go through the documentation for (System.out).println() and keep following the links untill you find what method is called in the argument object.
Campbell Ritchie wrote:
Did you only have an equals method? In that case it has been overridden incorrectly; if you look here, you will find out that you must override hashCode() too.
Stan Austin wrote:the issue i am having is that it is trying to Find my method, change_salary as a variable, when i want it to be a method being called
We have policies against very specific answers, and would do our best to remove them before you have a chance to see them. If you do see such an answer, you would have to be careful not to copy it.Stan Austin wrote:. . . because I'm certain my lecturer does google searches of his own assignment to find plagerism, and so i dont risk getting accused if someone posts a very specific answer . . .
You didn't follow enough links; it is toString that is called. You find that from where it said it behaves as if String#valueOf() had been called, and that link will tell you it calls toString.Campbell Ritchie wrote:What is wrong with line 33? . . . you find what method is called in the argument object.
nothing the line 33 is how i want my print formatted . . . i think it is the Employee method of the Employee class, isnt it?
You seem to be getting that to work nicely so far. . . the equals method, it compares two name to find out if they are the same right? . . . using Pauls Previous comment as a bit of a guide line
Liutauras Vilda wrote:]What you can say about 'if' statements? Are they really need to be 'if' in all cases? At least one I see a good candidate to swap it to 'else'
Paul Clements wrote:
Liutauras Vilda wrote:Not sure why you were using not a short-circuit operator, but rather '&'.
Paul Clements wrote:
Liutauras Vilda wrote:Not sure why you were using not a short-circuit operator, but rather '&'.
Because I thought the OP was attempting to check within a range i.e. BETWEEN two numbers. As such a short circuit operator would be wrong as it would not check both sides. I thought he had somehow set his own MIN and MAX. Time to move on I think.
Liutauras Vilda wrote:I think better would have been to admit mistake as this explanation isn't correct too
Paul Clements wrote:Because I thought the OP was attempting to check within a range i.e. BETWEEN two numbers. As such a short circuit operator would be wrong as it would not check both sides. I thought he had somehow set his own MIN and MAX. Time to move on I think.
My mistake. You are of course correct.Junilu Lacar wrote:The && operator only short circuits if the left side expression evaluates to false
Human fallibility.Junilu Lacar wrote:I'm not sure how you came to think that it does.
Paul Clements wrote:
Human fallibility.Junilu Lacar wrote:I'm not sure how you came to think that it does.
Junilu Lacar wrote:@OP: why do all your methods start with an assert Salary >= 0? Is this something you were taught to do? It is, very poor style.
Consider Paul's rocket mass heater. |