0% found this document useful (0 votes)
67 views

Empid Fname Lname Salary Jobtitle Grade: Empcounter

This document defines an Employee class with properties like ID, name, salary, etc. and methods to get/set these properties. It also defines a MainEmp class with a main method that creates Employee objects, gets data via user input, and prints the employee details. The MainEmp class demonstrates storing Employee objects in an array and looping through to get/print data for multiple employees.

Uploaded by

Lilaram Anjane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Empid Fname Lname Salary Jobtitle Grade: Empcounter

This document defines an Employee class with properties like ID, name, salary, etc. and methods to get/set these properties. It also defines a MainEmp class with a main method that creates Employee objects, gets data via user input, and prints the employee details. The MainEmp class demonstrates storing Employee objects in an array and looping through to get/print data for multiple employees.

Uploaded by

Lilaram Anjane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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