Answer:
Explanation:
This program should hold three functions for easy usage. The first will be a main function, the second will be a check function, the third will be a write function.
Main function:
First task should be to create the file using different functions which ae different for every language, like in java the function FileOutputStream will be used to make the file and PrintWriter can be used to enter data into the aforementioned file.
FileOutputStream fout=new FileOutputStream("employees.dat");
PrintWriter pw=new PrintWriter(fout);
or
PrintWriter pw=new PrintWirter(new FileOutputStream(“employees.dat”));
What we will do next is to run a do while loop which asks for the employee ID. Then it checks whether the ID is valid or not using the check function. If is comes out to be valid, then we will send the id to the write function where the further details of the employee will be asked. If it comes out to be invalid, an error message is to be printed stating that the input is wrong. Finally, we will ask the number that whether they want to enter more data. This condition will be put in the while and it will terminate the loop once the user says no more data.
Check function:
We will take a flag variable throughout the function which will keep track whether the number is valid or not.
Firstly, we will check that the entered id is less than 10 characters long. If no, then change the flag variable to invalid.
There are 5 valid id numbers that an entered id number must contain. These 5 can be entered into the system as an array.
Then in a loop we will check that whether one of these exists as a substring of the entered number.
boolean check=false;
//here check is the flag variable. If it remains false, it means that the entered ID is not valid.
if(length<=10)
{
String chch[]={"RE49762358","PR156125","OF45461","RE68566547","PR156984"};
for(int i=0;(i<5)&&(!check);i++)
{
int len1=chch[i].length();
for(int j=0;(j<=len-len1)&&(!check);j++)
{
String check12;
if(j+len+1==len)
check12=str.substring(j);
else
check12=str.substring(j,j+len1);
if(check12.equals(chch[i])){check=true;}
}
}
}
After the completion of loop, we can check return the flag variable to the main function.
Write function:
The print writer function written before shows it work here. First, we input the employee first name, last name and the employee hourly wage from the user. Do have a check statement for the hourly wage to be less than $45.50. If all conditions are fulfilled, then print all the details to the file.
pw.println(first_name);
pw.println(last_name);
pw.println(employee_id);
pw.println(hourly_wage);
pw.flush();