You are on page 1of 3

Array of Objects->

package myjava;
import java.util.Scanner;
public class Employee
{
private int empid;
private String fname;
private String lname;
private int salary;
private String jobtitle;
private String grade ;
static int empcounter;

public Employee() {
// TODO Auto-generated constructor stub
}
public Employee(int empid, String fname, String lname, int salary,
String jobtitle, String grade) {
this.setEmpid(empid);
this.setFname(fname);
this.setLname(lname);
this.setSalary(salary);
this.setJobtitle(jobtitle);
this.setGrade(grade);
}

public int getEmpid() {


return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;

}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public String getJobtitle() {
return jobtitle;
}
public void setJobtitle(String jobtitle) {
this.jobtitle = jobtitle;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public void getdata()
{
Scanner in=new Scanner(System.in);
System.out.println("enter empid");
empid=in.nextInt();
in.nextLine();
System.out.println("enter fname");
fname=in.nextLine();
in.nextLine();
System.out.println("enter lname");
lname=in.nextLine();
in.nextLine();
System.out.println("enter salary");
salary=in.nextInt();
in.nextLine();
System.out.println("enter jobtitle");
jobtitle=in.nextLine();
in.nextLine();
System.out.println("enter grade");
grade=in.nextLine();
in.nextLine();

}
public void print()
{
System.out.println("empid " +empid);
System.out.println("fname " +fname);
System.out.println("lname " +lname);

System.out.println("salary " +salary);


System.out.println("jobtitle " +jobtitle);
System.out.println("grade " +grade);
}
}

package myjava;
public class MainEmp {
public static void main(String[] args)
{
//Employee e= new Employee(01, "eropwe", "sdffs", 10000," testing",
'c');
MainEmp.disp();

//
//
//
//
'c');
//
//
//
//

}
public static void disp()
{
Employee e= new Employee(01, "abhi", "sav", 10000," testing", 'c');
Employee e1= new Employee(01, "abh1", "sav1", 10000," testing", 'c');
Employee e2= new Employee(01, "abh1", "sav3", 10000," testing", 'c');
Employee e3= new Employee(01, "abhi2", "1savr", 10000," testing",
e.print();
e1.print();
e2.print();
e3.print();
Employee []e=new Employee[3];
for(int i=0;i<3;i++)
{
e[i]=new Employee();
e[i].getdata();
}
for(int i=0;i<3;i++)
{
e[i].print();
}
}

You might also like