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
What are the benefits of using the engineering design process
Shalnov [3]

Answer:

Some of the benefits are tangible for they are visible in the design and production process, while the other benefits are intangible which may not be visible directly but result in improvement in the quality of product, better control over designing and production process, reduction of stress on the designers etc.

7 0
2 years ago
In using the drag coefficient care needs to be taken to use the correct area when determining the drag force. What is a typical
stealth61 [152]

Answer:

Explanation:

We know that Drag forceF_D

  F_D=\dfrac{1}{2}C_D\rho AV^2

Where

             C_D is the drag force constant.

                 A is the projected area.

                V is the velocity.

                ρ is the density of fluid.

Form the above expression of drag force we can say that drag force depends on the area .So We should need to take care of correct are before finding drag force on body.

Example:

 When we place our hand out of the window in a moving car ,we feel a force in the opposite direction and feel like some one trying to pull our hand .This pulling force is nothing but it is drag force.

6 0
3 years ago
A vector AP is rotated about the Z-axis by 60 degrees and is subsequently rotated about X-axis by 30 degrees. Give the rotation
Musya8 [376]

Answer:

R = \left[\begin{array}{ccc}1&0&0\\0&cos30&-sin30\\0&sin30&cos30\end{array}\right]\left[\begin{array}{ccc}cos 60&-sin60&0\\sin60&cos60&60\0&0&1\end{array}\right]

Explanation:

The mappings always involve a translation and a rotation of the matrix. Therefore, the rotation matrix will be given by:

Let \theta and \alpha be the the angles 60⁰ and 30⁰ respectively

that is \theta = 60⁰ and

\alpha = 30⁰

The matrix is given by the following expression:

\left[\begin{array}{ccc}1&0&0\\0&cos30&-sin30\\0&sin30&cos30\end{array}\right]\left[\begin{array}{ccc}cos 60&-sin60&0\\sin60&cos60&60\0&0&1\end{array}\right]

The angles can be evaluated and left in the surd form.

4 0
2 years ago
What did the US and USSR agree on in the INF Treaty? They agreed to reduce nuclear weapons. They agreed that new European nation
faust18 [17]

Answer:

they agreed to reduce nuclear weapons

4 0
2 years ago
Read 2 more answers
A company has a stack that emits a hazardous air pollutant. The ground mass concentration directly downwind of the plume sometim
fredd [130]

Answer:

do the wam wam

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Please describe a real situation in which you had to troubleshoot and fix the failure of a piece equipment/machine?
    5·1 answer
  • Can you reduce energy use without compromising people's basic needs (such as opening a car, cooking food, home lighting, electri
    13·1 answer
  • A block is sliding on a level surface of varying materials, and so its effective coefficient of friction is variable, 0.1t, wher
    6·1 answer
  • Consider a Carnot refrigeration cycle executed in a closed system in the saturated liquid-vapor mixture region using 0.96 kg of
    11·1 answer
  • Help thank you &lt;3 :DDD
    13·1 answer
  • Describe in detail the process of making a collapsable bowl.​
    11·1 answer
  • What is the difference between a modular home and a manufactured home?
    5·1 answer
  • What is another term for the notes that a reader can add to text in a word-processing document?
    11·2 answers
  • How frequently should vehicle registration be renewed?
    6·1 answer
  • If an object has the same number of positive and negative charges, its electrical charge is
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!