• Post Reply Bookmark Topic Watch Topic
  • New Topic

Value will not return; when calling file.  RSS feed

 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am running a code of "Employee.java" ; It will return me Name,Salary and HireYear of employee.
CODE Of "Employee.java"
----------------------------------------------------------------------
package Comp;
public class Employee
{
private String name;
private double salary;
private int hireYear;


public Employee ()
{
this("No Name",100,2000);
}
public Employee(String theName, int theSalary, int theHireYear)
{
name=theName;
salary = theSalary;
hireYear= theHireYear;
}

public String toString()
{
return "name\t" +name + "\t. salary is " +salary+"\t Hire Year is " + hireYear+ salary;


}
public void raiseSalary(int byPerc)
{
double perc = byPerc *0.01;
salary=(salary*perc) + salary;
}

public static void main(String[] args)
{
Employee test = new Employee();
test.salary=100;
System.out.println(test.toString());
test.raiseSalary(10);
System.out.println(test.toString());
}


}
--------------------------------------------------------------------------
But When I am importing this file to "EmployeeTester.java"

It will displayed me only "name, & "hireyear".

Here is the code of "EmployeeTester.java"

-------------------------------------------------------------------------

public class EmployeeTester
{
public static void main (String[] args)
{
Employee e1= new Employee("B1",100.0,1998);

e1.raiseSalary(5);


System.out.println(e1.toString());

}

}
---------------------------------------------------------------------

Please help me... to find out where I went wroung
Thanks,
Divya
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by divya sharma:
...It will displayed me only "name, & "hireyear"...

This wouldn't even compile for me until I changed the double 100.0 to an int 100 as required by the constructor...

Employee e1 = new Employee("B1",100.0,1998);
...changed to...
Employee e1 = new Employee("B1",100,1998);

After that, it worked fine. (Well, the printing worked fine. There are still some other issues to work out.)
[ April 19, 2007: Message edited by: marc weber ]
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fo your help
 
Sidd Kulk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did it compile? Coz you said that it isn't running as expected.
[ April 20, 2007: Message edited by: Sidd Cool ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!