In Jgrasp make copies of the Employee.java and EmployeeData.java files from less
ID: 3699766 • Letter: I
Question
In Jgrasp make copies of the Employee.java and EmployeeData.java files from lesson 7 to enhance them for this project. 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.
//class Employee.java
public class Employee
{
public static void main(String[] args)
{
EmployeeData emp=new EmployeeData();
emp.InputData();
}
}
//EmployeeData.java
import java.util.*;
public class EmployeeData
{
//variables
private String FirstName;
private String LastName;
private int empId;
private double wages;
private String a;
//constructor
public EmployeeData()
{
//values
this.FirstName=FirstName;
this.LastName=LastName;
this.empId=empId;
this.wages=wages;
}
//method to get input
public void InputData()
{
//creates instance for scanner
Scanner inp = new Scanner(System.in);
//do loop
do
{
//gets the user input
System.out.println("Please enter the employee's data separated by exactly one space first name, last name, numeric ID and hourly wage:");
//get the first name
FirstName =inp.next();
//get the last name
LastName=inp.next();
//get the empid
empId =inp.nextInt();
//get the wages
wages =inp.nextDouble();
displayInformation();
//do wish to continue message
System.out.println("Continue(Yes/No)");
a=inp.next();
//while loop
}while(a.equalsIgnoreCase("yes"));
}
//defines to display
public void displayInformation()
{
//statement to print
System.out.println("EmployeeName:"+FirstName+LastName);
System.out.println("ID:"+empId);
System.out.println("Hourly Wage:"+wages);
}
}
Thank you will upvote!
Explanation / Answer
Employee.java : public class Employee { public static void main(String[] args) { EmployeeData emp=new EmployeeData(); emp.InputData(); emp.displayInformation(); } } EmployeeData.java : import java.util.*; public class EmployeeData { //variables private String FirstName; private String LastName; private int empId; private double wages; private String a; private static int i = 0; private String[] firstName = new String[100]; private String[] lastName = new String[100]; private int[] emp = new int[100]; private double[] wage = new double[100]; //constructor public EmployeeData() { //values this.FirstName=FirstName; this.LastName=LastName; this.empId=empId; this.wages=wages; } //method to get input public void InputData() { //creates instance for scanner Scanner inp = new Scanner(System.in); //do loop do { //gets the user input System.out.println("Please enter the employee's data separated by exactly one space first name, last name, numeric ID and hourly wage:"); //get the first name FirstName =inp.next(); firstName[i] = FirstName; //get the last name LastName=inp.next(); lastName[i] = LastName; //get the empid empId =inp.nextInt(); emp[i] = empId; //get the wages wages =inp.nextDouble(); wage[i] = wages; i++; System.out.println("Continue(Yes/No)"); a=inp.next(); //while loop }while(a.equalsIgnoreCase("yes")); } //defines to display public void displayInformation() { //statement to print for (int j = 0; jRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.