1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tankabanditka [31]
3 years ago
13

Your Java program will be reading input from a file name strInput.txt. Each record contains String firstname String lastName Str

ing strSalary (which will be converted to a double if it's valid- see below) char status String cityState (city and state and combine together but separated by a comma)
Sample input:
Ira Rudowsky 87654.32 F Brooklyn.NY
Jane Doe 987609.87 F NY NY
Mickey Mantle 345678.30 D Orlando FL
Fran Young 10456A.82 G Boston MA
Richard Clark 67890.32 D
Serena liams 1295609.87 D Denver, CO
Read from the file one record at a time and process as follows:
1. Any record whose status code is neither D or F should be written to the screen indicating the error. The next record should be read in
2. If the status code is D or F, validate the salary that it contains only digits and one decimal point 3 positions from the right (indicating cents)
a. If the salary is invalid, print the entire record to the screen, indicating the error (char at position x is not a digit or period is missing or period is in the wrong position)
b. If the salary is valid, convert it to a double c. If the status code is D, compute the bonus (double) as 12.5% of salary and 18% if the status code is F
3. Separate the cityState into two individual Strings named city and state. Use the comma to extract the city portion before the comma and the state after the comma
4. Each record that has a status of D should be written to a file named strOutputD and those record with status of F should be written to a file named strOutputRE.
a. For both files, each record printed should include firstName, lastName, status, salary, bonus, city and state
5. When all records have been read in, print to the screen the number of D, F and incorrect records processed
Engineering
1 answer:
stiks02 [169]3 years ago
6 0

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);

}

}

You might be interested in
A hollow steel tube with an inside diameter of 100 mm must carry a tensile load of 400 kN. Determine the outside diameter of the
Olegator [25]

Answer:

119.35 mm

Explanation:

Given:

Inside diameter, d = 100 mm

Tensile load, P = 400 kN

Stress = 120 MPa

let the outside diameter be 'D'

Now,

Stress is given as:

stress = Load × Area

also,

Area of hollow pipe = \frac{\pi}{4}(D^2-d^2)

or

Area of hollow pipe = \frac{\pi}{4}(D^2-100^2)

thus,

400 × 10³ N = 120 × \frac{\pi}{4}(D^2-100^2)

or

D² = tex]\frac{400\times10^3+30\pi\times10^4}{30\pi}[/tex]

or

D = 119.35 mm

7 0
3 years ago
Read 2 more answers
¿Qué son alimentos funcionales?
Mnenie [13.5K]
DescripciónAlimentos funcionales son aquellos alimentos que son elaborados no solo por sus características nutricionales sino también para cumplir una función específica como puede ser el mejorar la salud y reducir el riesgo de contraer enfermedades
4 0
3 years ago
What would happen if an exposed film was accidentally placed in the fixer before being placed in the developer
Eduardwww [97]
Do you still want this answered
5 0
3 years ago
Supón que tienes que calcular el centro de gravedad de una pieza
Anton [14]

Answer:huh?

Explanation:

4 0
4 years ago
Ada Lovelace Day, celebrating Ada, Countess of Lovelace as the first computer programmer, is traditionally celebrated on the sec
snow_lady [41]

Ada Lovelace Day, celebrating Ada, Countess of Lovelace as the first computer programmer, is traditionally celebrated on the second Tuesday of October each year is given below

Explanation:

1.The second Tuesday of every October marks Ada Lovelace Day, a day founded in 2009 by technologist Suw Charman-Anderson, to celebrate the achievements of women in Stem careers (science, technology, engineering and mathematics), and was created in memory of one in particular: Ada Lovelace, the first computer programmer.

2.Ada Lovelace: The First Computer Programmer. Ada Lovelace has been called the world's first computer programmer. ... By 1834 he had moved on to design his Analytical Engine, the first general purpose computer, which used punch cards for input and output. This machine also lacked financing and was never built.

3.Born two centuries ago, Ada Lovelace was a pioneer of computing science. She took part in writing the first published program and was a computing visionary, recognizing for the first time that computers could do much more than just calculations.

4.Through Babbage, Ada began studying advanced mathematics with University of London professor Augustus de Morgan. Ada was fascinated by Babbage's ideas. Known as the father of the computer, he invented the difference engine, which was meant to perform mathematical calculations.

5.It's Ada Lovelace Day today which means it is a time to celebrate the achievements of women working in the fields of science, technology, engineering and mathematics (STEM). Now in its eighth year, the annual celebration was founded by journalist and software activist Suw Charman-Anderson.

6 0
3 years ago
Other questions:
  • Decide whether or not the Final Value Theorem is applicable to the following functions. If not, indicate why you cannot apply it
    11·1 answer
  • 9. What is the Tribal Assistance Coordination Group (TAC-G)?
    11·1 answer
  • Consider a system with two tasks, Task1 and Task2. Task1 has a period of 200 ms, and Task2 has a period of 300 ms. All tasks ini
    5·1 answer
  • A rigid tank holds 10 lbm of 160 °F water. If the quality of the water is 0.5 then what is the pressure in the tank and volume o
    15·1 answer
  • a triangle is defined by the three vertices. write the following functions of the triangle class assume that the point class has
    7·1 answer
  • What are the complex structures and the advantages and disadvantages
    6·1 answer
  • Which of these parts of a cell phone is least likely to be found on the phone's circult board?
    5·1 answer
  • This is the top part of the picture. I need someone to put the correct letter by the word !
    5·2 answers
  • Engineering Specificaitons is ...
    9·1 answer
  • How many squares titles (20cm x 20cm) are needed to coat the sides and base of a pool which is 10m long, 6 meter wide and 3m dee
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!