Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

5. Arranging for the training facility and room.

Answered: 1 week ago