• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Println and Scanner

 
Mike Atoms
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like for this EmployeeTest app to receive from the user 2 sets of information. Each includes the first name, last name and monthly salary for an employee. Then I want the program to calculate the employees yearly salary and then give them a 10% raise. My coding is only taking information for 1 employee and the raise is not being properly calculated nor displayed back to me.



I've tried several things but to no avail. Please help me understand why this isn't working as I would like it to. Below is an example of the output I am receiving.

run:
0.0
0.0
Enter employee first name: Mike
Enter employee last name: Atoms
Enter monthly salary: 1000
Employee Named: Mike Yearly Salary = 0.0
Employee Named: Mike Yearly Salary = 0.0
Lets give them a ten percent raise!!
Employee named MikeNew Salary = 0.0
Employee named MikeNew Salary = 0.0
BUILD SUCCESSFUL (total time: 10 seconds)

Thanks for the help!
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you calculate the yearly salary, you do so before setting the Employee object's monthly salary. Thus when you ask the Employee object for its monthly salary, I bet that it's returning 0 for a default value. Solution: only do the calculation after you've set both Employee monthly salaries.
 
Mike Atoms
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete,

I appreciate the help. I changed how I attacked the problem. I removed the scanner and just set the employees info manually in the code. The code is below.

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You ought to have a toString method in your Employee class. Then you simply write System.out.println(emp1);
 
Greg Stevens
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this raise temporary? The new salary is never assigned to an instance variable.

EDIT: I see the salary is stored as a monthly salary. Still, you could do your output display with the local variables
newYearlySalary1 and newYearlySalary2, but, if you don't change the monthlySalary instance variables the raise
will not take effect.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic