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
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started