Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the two JAVA scripts below to achieve the following: Instead of printing

ID: 3856020 • Letter: M

Question

Modify the two JAVA scripts below to achieve the following: Instead of printing each Employee’s data after it is entered, load the object to an array of Employee objects containing the data input by the user. At the end of the EmployeeData program use a for loop to print a list of all the Employee objects’ information after all have been input.

1.

public class Employee
{
public static void main(String[] args)
{
EmployeeData employ = new EmployeeData();
employ.getEmployeeData();
// setting instance and calling function
}
}

2.

import java.util.Scanner;
public class EmployeeData
{
private String firstName;
private String lastName;
private int ID;
private double wage;
private String a;
// declaring variables
public EmployeeData()
{
this.firstName = firstName;
this.lastName = lastName;
this.ID = ID;
this.wage = wage;
// setting variables
}

public void getEmployeeData()
{
Scanner input = new Scanner(System.in);
do //loop for inputs
{
System.out.println("Please enter the Employee's Data separated by exactly one space first name, last name, numeric ID and hourly wage");
firstName = input.next();
lastName = input.next();
ID = input.nextInt();
wage = input.nextDouble();
displayData();

System.out.println("Do you want another input? y/n");
a = input.next();
}   
while(a.equalsIgnoreCase("y"));
}// while loop for conditions to input more than one employee data

public void displayData()
{
System.out.println("EmployeeName: " + firstName + " " + lastName + " ID: " + ID + " Hourly wage: " + wage);
// displaying information
}
}    

Explanation / Answer

EmployeeData.java


import java.util.Scanner;
public class EmployeeData {
private String firstName;
private String lastName;
private int ID;
private double wage;

// declaring variables
public EmployeeData() {
this.firstName = firstName;
this.lastName = lastName;
this.ID = ID;
this.wage = wage;
// setting variables
}

public void getEmployeeData() {
Scanner input = new Scanner(System.in);

System.out.println("Please enter the Employee's Data separated by exactly one space first name, last name, numeric ID and hourly wage");
firstName = input.next();
lastName = input.next();
ID = input.nextInt();
wage = input.nextDouble();
}

public void displayData() {
System.out.println("EmployeeName: " + firstName + " " + lastName + " ID: " + ID + " Hourly wage: " + wage);
// displaying information
}
}

___________________

Employee.java

import java.util.ArrayList;
import java.util.Scanner;

public class Employee {
public static void main(String[] args) {

//Declaring variables
String s;
int i = 0;

//Creating an ArrayList which holds EmployeeData class objects
ArrayList < EmployeeData > arl = new ArrayList < EmployeeData > ();

// Scanner object is used to get the inputs entered by the user
Scanner input = new Scanner(System.in);

do {
//Creating EmployeeData class instance
EmployeeData employ = new EmployeeData();

//Getting each Employee info by calling the method
employ.getEmployeeData();

//Adding each EmployeeData into an ArrayList
arl.add(employ);

System.out.println("Do you want another input? y/n");
s = input.next();
} while (s.equalsIgnoreCase("y"));

//Displaying the Employee data using For-Each loop
for (EmployeeData ed: arl) {
System.out.println("****** Employee " + (++i) + " info *******");
ed.displayData();
}
}
}

________________________

Output:

Please enter the Employee's Data separated by exactly one space
first name, last name, numeric ID and hourly wage
Sachin Tendulkar 111 12
Do you want another input? y/n
y
Please enter the Employee's Data separated by exactly one space
first name, last name, numeric ID and hourly wage
Rahul Dravid 222 13
Do you want another input? y/n
y
Please enter the Employee's Data separated by exactly one space
first name, last name, numeric ID and hourly wage
Virat Kohli 333 14
Do you want another input? y/n
y
Please enter the Employee's Data separated by exactly one space
first name, last name, numeric ID and hourly wage
Ricky Pointing 444 12
Do you want another input? y/n
y
Please enter the Employee's Data separated by exactly one space
first name, last name, numeric ID and hourly wage
Pat Simcox 555 11
Do you want another input? y/n
n
****** Employee 1 info *******
EmployeeName: Sachin Tendulkar
ID: 111
Hourly wage: 12.0
****** Employee 2 info *******
EmployeeName: Rahul Dravid
ID: 222
Hourly wage: 13.0
****** Employee 3 info *******
EmployeeName: Virat Kohli
ID: 333
Hourly wage: 14.0
****** Employee 4 info *******
EmployeeName: Ricky Pointing
ID: 444
Hourly wage: 12.0
****** Employee 5 info *******
EmployeeName: Pat Simcox
ID: 555
Hourly wage: 11.0


_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote