Question: Create a class Employee in Employee.java and stores the name, age, designation and salary for an employee. Implement the toString() method in Employee so that

Create a class Employee in Employee.java and stores the name, age, designation and salary for an employee. Implement the toString() method in Employee so that once it is called, it can print fields of the employee separated by a comma. Create a program called EmployeeSystem.java that will create an array of employees and take all employee information (name, age, designation, salary) from the console and set values to each employee object. There will also be a static method called printEmployee() that will print information of all employees.

import java.util.Scanner;

public class EmployeeSystem {

public static void printEmployee(Employee[] employees){

/* write your code here */

}

public static void main(String args[]) {

Employee[] emp = new Employee[3];

/* Write your code : Initialization of the objects in the array */

Scanner scan = new Scanner(System.in);

for (int i=0;i<3;i++) {

System.out.println("Enter name:");

String name=scan.next();

System.out.println("Enter age:");

int age=scan.nextInt();

System.out.println("Enter designation:");

String designation=scan.next();

System.out.println("Enter salary:");

double salary=scan.nextDouble();

}

for (int i = 0; i < emp.length; i++) {

/* Write your code : Set values to each employee object by reading the input from console*/

}

scan.close();

printEmployee(emp);

}

}

import java.util.Scanner;

public class Employee {

/*Fill blanks here to define the fields of Employee*/

public void setEmployee(String empName, int empAge, String empDesig, double empSalary) {

name=empName;

age = empAge;

designation = empDesig;

salary = empSalary;

}

public String toString(Employee[] emp) {

/*write codes here*/

}

}


Step by Step Solution

3.43 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this problem you need to create two classes Employee and EmployeeSystem Heres a stepbystep guide and complete implementation Step 1 Define th... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!