Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make copies of the Employee.java and EmployeeData.java files from lesson 7 to enhance them for this project. Instead of printing each Employees data after it

Make copies of the Employee.java and EmployeeData.java files from lesson 7 to enhance them for this project. Instead of printing each Employees 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. This is a sample run:

image text in transcribed

// Below shows Employee.java

public class Employee { private String firstName, lastName; private int employeeID; private double hourlyWage;

public Employee(String firstName, String lastName, int employeeID, double hourlyWage) { this.firstName = firstName; this.lastName = lastName; this.employeeID = employeeID; this.hourlyWage = hourlyWage; }

public void display() { System.out.println(" \tEmployee name: " + firstName + " " + lastName + " \tID: " + employeeID + " \tHourly wage: " + hourlyWage); } }

-------------------------------------------------------------------------------------------------------------------------------------------

//Below is EmployeeData.java

import java.util.Scanner; public class EmployeeData { public static void main(String[] args) { char response; int x; String answer; String userInput; int spacePosition; int spacePosition2; int spacePosition3; String employeeIDString; String hourlyWageString; Scanner keyboard = new Scanner(System.in);

final String moreInput = "Are you finished? (y)"; final String instruction = "Please enter the Employee's Data separated by exactly " + "one space first name, last name, numeric ID and hourly wage For example:" + " John Smith 123456 12.50 ";

do { System.out.println(instruction); userInput = keyboard.nextLine();

spacePosition = userInput.indexOf(' ');//Find the first space String firstName = userInput.substring(0, spacePosition);//Extract firstName starting from 0 to where the first space spacePosition2 = userInput.indexOf(' ', ++spacePosition);// Find the 2nd space starting from where the first space ended. The increment ++ means to skip the space. String lastName = userInput.substring(spacePosition, spacePosition2);//Extract lastName from the last space to the 2nd space. spacePosition3 = userInput.indexOf(' ', ++spacePosition2);//Same as line 39 above employeeIDString = userInput.substring(spacePosition2, spacePosition3); int employeeID = Integer.parseInt(employeeIDString);//Because employeeID is integer, it has to be converted from String using ParseInt. hourlyWageString = userInput.substring(++spacePosition3);//The starting point to find the hourlyWage is after the 3rd space to the end, where is no more space. double hourlyWage = Double.parseDouble(hourlyWageString);

Employee employee = new Employee(firstName, lastName, employeeID, hourlyWage); employee.display();

System.out.println(moreInput); response = keyboard.nextLine().charAt(0);

} while(response == 'n'); } }

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions