File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help with Println and Scanner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Println and Scanner" Watch "Help with Println and Scanner" New topic
Author

Help with Println and Scanner

Mike Atoms
Greenhorn

Joined: Aug 29, 2009
Posts: 12
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Aug 29, 2009
Posts: 12
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

Joined: Oct 13, 2005
Posts: 36499
    
  16
You ought to have a toString method in your Employee class. Then you simply write System.out.println(emp1);
Greg Stevens
Ranch Hand

Joined: Jul 23, 2009
Posts: 41
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with Println and Scanner
 
Similar Threads
Help with Constructor!
java.lang.reflect.UndeclaredThrowableException
System.out.printf
Scanner class question
Class declaration problem.