Thursday, 16 January 2014

Java Creating Classes and Package

/*Creating Java Class and Using getter/setter method..
Save the file with EmployeeTest.java in the package "com.example" and also make another package with name 

"com.example.domain See below to have the Employee.java file"
 */
package com.example;
/**
 *
 * @author Aqib
 */
import com.example.domain.Employee;
public class EmployeeTest {
    private int eid;
    private String ename;
    private String essn;
    private double esalary;

    
    public void setEid(int eid) {
        this.eid = eid;
    } 

    public void setEname(String ename) {
        this.ename = ename;
    }   

    public void setEssn(String essn) {
        this.essn = essn;
    }   

    public void setEsalary(double esalary) {
        this.esalary = esalary;
    }
    public static void main(String[] args) {
        // TODO code application logic here
        Employee eobj = new Employee();
        eobj.setEid(101);
        eobj.setEname("Aqib");
        eobj.setEssn("120-099-877");
        eobj.setEsalary(120_345.87);
        System.out.println("Employee Id is " + eobj.getEid());
        System.out.println("Employee Name is " + eobj.getEname());
        System.out.println("Emploee SSN number is " + eobj.getEssn());
        System.out.println("Employee Salary is " + eobj.getEsalary());
    }
}


/*Employee.java file*/

package com.example.domain;

public class Employee {
public int eid;
public String ename,essn;
public double esalary;
    public int getEid() {
        return eid;
    }

    public void setEid(int eid) {
        this.eid = eid;
    }

    public String getEname() {
        return ename;
    }

    public void setEname(String ename) {
        this.ename = ename;
    }

    public String getEssn() {
        return essn;
    }

    public void setEssn(String essn) {
        this.essn = essn;
    }

    public double getEsalary() {
        return esalary;
    }

    public void setEsalary(double esalary) {
        this.esalary = esalary;
    }

    public Employee() {
    }

    public static void main(String[] args) {
    
}
}

No comments:

Post a Comment