Hi, i don't know what i did not do right here.
i created two classes; Employee and Employment and i and then i created an
array of 5 objects of the Employee class but the output that i am getting is
errorneous for me. Please help me . This is the code:
public class Employee
{
private int EmpNum;
private double EmpSalary;
private int EmpAge;
public Employee(int num, double sal, int age)
{
this.EmpNum=num;
this.EmpSalary=sal;
this.EmpAge=age;
}
public int Age()
{
return EmpAge;
}
public double Salary()
{
return EmpSalary;
}
public int Num()
{
return EmpNum;
}
}
public class Employment
{
public static void main(String[] args) throws Exception
{
Employee[] Worker= new Employee[5];
int Age;
int Number;
double Salary;
int x;
System.out.println("This is for five workers in my company"+"\n");
for(x=0;x<5;x++)
{
System.out.println("\nWorker"+(x+1)+"\n");
System.out.println("Enter your age:");
Age=(int)System.in.read();
System.in.read();System.in.read();
System.out.println("Worker's Number:");
Number=(int)System.in.read();
System.in.read();System.in.read();
System.out.println("Worker's Salary:");
Salary=(double)System.in.read();
System.in.read();System.in.read();
Worker[x]=new Employee(Number,Salary,Age);
}
System.out.println("--------------------------------------------------------------------");
for(x=0;x<5;x++)
{
System.out.println("\n worker :"+(x+1)+"\n" );
System.out.println("Age:"+Worker[x].Age()+"\n Number:"+Worker[x].Num()+"\n
Salary:"+Worker[x].Salary());
}
}
}
Thank you.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---