• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Value will not return; when calling file.

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks fo your help
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic