You are to design class called Employee whose members are as given below:

Data members:
char *name
long int ID
A constructor:
// initialize data members to the values passed to the constructor
Methods:
get Person (name, id) //allows user to set information for each person
A function called Print () that prints the data attributes of the class.

Show the working of class in a driver program (one with main).

Respuesta :

ijeggs

Answer:

//The Employee Class

public class Employee {

   char name;

   long  ID;

//The constructor  

public Employee(char name, long ID) {

       this.name = name;

       this.ID = ID;

   }

//Method Get Person

   public void getPerson (char newName, long newId){

       this.ID = newName;

       this.ID = newId;

   }

//Method Print

   public void print(){

       System.out.println("The class attributes are: EmpName "+name+" EmpId "+ID);

   }

}

The working of the class is shown below in another class EmployeeTest

Explanation:

public class EmployeeTest {

   public static void main(String[] args) {

       Employee employee1 = new Employee('a', 121);

       Employee employee2 = new Employee('b', 122);

       Employee employee3 = new Employee('c', 123);

       employee1.print();

       employee2.print();

       employee3.print();

   }

}

In the EmployeeTest class, Three objects of the Employee class are created.

The method print() is then called on each instance of the class.