Answer:
The program requires that you have the specified input files and it reads from each file at a time and processes salary in digits, states the city, state and bonus with respective first and last name as requested in the question. Note that you must have access to the mentioned output files for the program to work properly. Below is the java version of the program.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
class Driver
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner sc = new Scanner(new File("strInput.txt"));
PrintWriter pd = new PrintWriter(new File("strOutputD"));
PrintWriter prf = new PrintWriter(new File("strOutputRF"));
String firstname = "", lastname = "", strSalary = "", status = "", cityState = "", city = "", state = "";
double salary = 0, bonus = 0;
int incorrectRecords = 0;
int dRecords = 0;
int fRecords = 0;
while(sc.hasNextLine())
{
firstname = sc.next();
lastname = sc.next();
strSalary = sc.next();
status = sc.next();
cityState = sc.next();
if(!status.equals("D") && !status.equals("F"))
{
System.out.println("Records is neither D nor F. Skipping this...");
incorrectRecords++;
continue;
}
else if(status.equals("D") || status.equals("F"))
{
char c = ' ';
int i = 0;
for(i=0; i<strSalary.length() && c != '.'; i++)
{
c = strSalary.charAt(i);
if(!Character.isDigit(c))
{
System.out.println("Char at position " + (i+1) + " in salary is not a digit");
incorrectRecords++;
continue;
}
}
if(c == '.')
{
if(i+1 == strSalary.length()-1)
{
if(!Character.isDigit(strSalary.charAt(i)))
{
System.out.println("Char at position " + (i+1) + " in salary is not a digit");
incorrectRecords++;
continue;
}
if(!Character.isDigit(strSalary.charAt(i+1)))
{
System.out.println("Char at position " + (i+1+1) + " in salary is not a digit");
incorrectRecords++;
continue;
}
}
else
{
System.out.println("Period is in the wrong position. Expected at " + (strSalary.length()-3) + " but found at " + (i+1));
continue;
}
}
city = cityState.split(",")[0];
state = cityState.split(",")[1];
salary = Double.parseDouble(strSalary);
if(status.equals("D"))
{
bonus = salary * 0.125;
dRecords++;
pd.write(firstname + " " + lastname + " " + status + " " + salary + " " + bonus + " " + city + " " + state);
}
else
{
bonus = salary * 0.18;
fRecords++;
prf.write(firstname + " " + lastname + " " + status + " " + salary + " " + bonus + " " + city + " " + state);
}
}
}
System.out.println("No of D records : " + dRecords);
System.out.println("No of F records : " + fRecords);
System.out.println("No of incorrect records : " + incorrectRecords);
}
}