class Employee
{
public string name;
public int salary;
public int joiningDate;
public Employee()
{
}
public Employee(string name, int salary, int joiningDate)
{
this.name = name;
this.salary = salary;
this.joiningDate = joiningDate;
}
public void GetEmployeeData()
{
{
Console.WriteLine("Enter the name of employee: ");
name = Convert.ToString(Console.ReadLine());
Console.WriteLine("Enter the salary of employee: ");
salary = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the date of joining of employee: ");
joiningDate = Convert.ToInt32(Console.ReadLine());
}
}
public void DisplayEmployee()
{
Console.WriteLine("The name of employee is: "+ name);
Console.WriteLine("The salary of employee is: "+salary);
Console.WriteLine("The date of joining of employee is: "+joiningDate);
}
}
class Program
{
static void Main(string[] args)
{
Employee[] e = new Employee[10];
for(int i = 0; i < 10; i++)
{
Console.WriteLine($"Enter the data of employee with id: {i} *****************************************");
e[i] = new Employee();
e[i].GetEmployeeData();
}
Console.WriteLine("***********The data of given employees is: ");
for(int i = 0; i < 10; i++)
{
e[i].DisplayEmployee();
}
}
}
Excellent share.
public class Employee { private String name; private int salary; private String joiningDate; public Employee(String name, int salary, String joiningDate) { super(); this.name = name; this.salary = salary; this.joiningDate = joiningDate; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } public String getJoiningDate() { return joiningDate; } public void setJoiningDate(String joiningDate) { this.joiningDate = joiningDate; } @Override public String toString() { return "Employee [name=" + name + ", salary=" + salary + ", joiningDate=" + joiningDate + "]"; } }
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
Employee[] obj= new Employee[10];
String name ;
int salary ;
String joiningDate;
for(int i = 0; i < obj.length; i++) {
System.out.print("Enter name of Employee "+(i+1)+" :");
name=input.next();
System.out.print("Enter salary : ");
salary=input.nextInt();
System.out.print("Enter joiningDate: ");
joiningDate=input.next();
obj[i]= new Employee(name, salary, joiningDate);
}
for(int i = 0; i < obj.length; i++) {
System.out.println(obj[i]);
}
}
}