Write an application that allows a user to enter the employee names and their hi
ID: 3599155 • Letter: W
Question
Write an application that allows a user to enter the employee names and their hire dates of up to 10 employees for Company A.
Continue to prompt the user for employee names and their hire dates until the user enters the sentinel value “STOP” for an employee name or has entered 10 employee names, whichever comes first.
When the user is done entering employee names, calculate how many employee names were entered, and then show the names entered.
In a loop, continuously ask the user to type one of the employee names and display the hire date for the employee or display a message if the employee name was not entered before.
The loop continues until the user enters “STOP” for the employee name. Save the application as EmployeeHireDate.java.
(please indent the code too)
Explanation / Answer
import java.util.*; // to use Scanner class
import java.lang.String; //to use String class and its methods
public class EmployeeHireDate
{
public static void main(String args[])
{
int k=0;
Scanner obj=new Scanner(System.in);
String[] name=new String[10]; // making String array to store employee names
String[] date=new String[10]; // making String array to store Hire Dates
for(int i=0;i<10;i++)
{
System.out.println("Enter employee name :");
name[i]=obj.nextLine(); // taking employee name as input
if(name[i].equals("STOP") || name[i].equals("stop")) //given termination condition in question
{
break;
}
for(int j=0;j<i;j++)
{
if(name[i].equals(name[j])) // compare if Employee name is already enterd or not
{
System.out.println("Employee Name already entered..");
System.out.println("Enter Employee Name Again");
name[i]=obj.nextLine();
}
}
System.out.println("Enter Hire Date :");
date[i]=obj.nextLine(); // taking Hire Date as input
k++;
}
System.out.println();
System.out.println(k+" Employee Names are Entered.. "); //counting number of employees entered
if(k==0)
{
System.exit(0); // if no one employee is entered
}
System.out.println("entered Names and Their Hire Dates :");
for(int i=0;i<k && name[i]!="STOP";i++)
{
System.out.print(name[i]); //displaying employees names
System.out.print(" "+date[i]); //displaying hire dates
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.