dear friends i have created 3
java files
1) Employee
2) Nameof_emp
3) Emploeetest which has main method
my problem is how should i overload tostring method of Nameof_emp
to get full name of person
Here is Employee class
package My_emp_project;
public class Employee {
private Nameof_emp name;
private double in_time;
private double out_time;
private double work_h;
public Employee(
String s1, String s2, String s3, double y, double z) {
this.name = new Nameof_emp(s1, s2, s3);
in_time = y;
out_time = z;
}
public Employee(String s1, String s2, double y, double z) {
this.name = new Nameof_emp(s1, s2);
in_time = y;
out_time = z;
}
public Employee(String s1, double y, double z) {
this.name = new Nameof_emp(s1);
in_time = y;
out_time = z;
}
protected Nameof_emp setnameof_emp(String s1,String s2,String s3) {
return new Nameof_emp(s1,s2,s3);
}
protected Nameof_emp setnameof_emp(String s1,String s2) {
return new Nameof_emp(s1,s2);
}
protected Nameof_emp setnameof_emp(String s1) {
return new Nameof_emp(s1);
}
protected void set_in_time(double in) {
this.in_time = in;
}
protected void set_out_time(double out) {
this.out_time = out;
}
protected double set_work_hour() {
work_h = (out_time) - (in_time);
return work_h;
}
protected String get_work_hour() {
return Double.toString(work_h);
}
public String toString() {
return "my Dear\t " + this.name + "\n your intime:\t" + this.in_time +
"\n outtime\t" + this.out_time + "\n work hour:\t" +
Double.toString(this.set_work_hour());
}
}
now Employeename class
package My_emp_project;
public class Nameof_emp {
private String first_n;
private String middle_n;
private String Last_n;
public Nameof_emp(String x, String y, String z) {
first_n = x;
middle_n = y;
Last_n = z;
}
public Nameof_emp(String x, String y) {
first_n = x;
Last_n = y;
}
public Nameof_emp(String x) {
first_n = x;
}
public String toString() {
return first_n;
}
}
Employeetest class
package My_emp_project;
public class Employeetest {
public static void main(String[] args) {
Employee g2 = new Employee("jayesh","Khanvilkar", 9.45, 13.45);
Employee g1 = new Employee("vivek","padh", 9.23, 13.45);
System.out.println();
System.out.println(g1);
System.out.println(g2);
}
}
o/p is
my Dear vivek
your intime:9.23
outtime13.45
work hour:4.219999999999999
my Dear jayesh
your intime:9.45
outtime13.45
work hour:4.0