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
Tesla Is the best ELECTRIC car brand, Change my mind
pochemuha

Answer:You are correct, no need to change.

Explanation:

5 0
3 years ago
Read 2 more answers
What to you do if you have a flat tirer
Vika [28.1K]

Answer: change the tires

Explanation: you can’t drive on a flat tire

6 0
3 years ago
How do we find percentage error in measuring voltage across a resistor​
Black_prince [1.1K]

Answer:

  use the percentage error relation

Explanation:

The percentage error in anything is computed from ...

  %error = ((measured value)/(accurate value) -1) × 100%

__

The difficulty with voltage measurements is that the "accurate value" may be hard to determine. It can be computed from the nominal values of circuit components, but there is no guarantee that the components actually have those values.

Likewise, the measuring device may have errors. It may or may not be calibrated against some standard, but even measurement standards have some range of possible error.

6 0
2 years ago
Read 2 more answers
Why is it called field effect transistor​
Mrac [35]

Answer:

The field-effect transistor (FET) is a type of transistor which uses an electric field to control the flow of current.

FET is named field effect transistor as field effect is producing, but in BJT also field effect will produce. :)

5 0
3 years ago
investigation, determine when the Elastic Potential Energy is zero. Make sure you test your idea with several masses, all three
nata0808 [166]

Elastic Potential Energy is zero detailed description is given below.

Explanation:

  • It is the energy stored in stretched or compressed elastic materials. This also means that elastic potential energy is zero in objects that have not been stretched or compressed.
  • To determine the gravitational potential energy of an object, a zero height position must first be arbitrarily assigned. Typically, the ground is considered to be a position of zero height. But this is merely an arbitrarily assigned position that most people agree upon. Since many of our labs are done on tabletops, it is often customary to assign the tabletop to be the zero height position. Again this is merely arbitrary. If the tabletop is the zero position, then the potential energy of an object is based upon its height relative to the tabletop. For example, a pendulum bob swinging to and from above the tabletop has a potential energy that can be measured based on its height above the tabletop. By measuring the mass of the bob and the height of the bob above the tabletop, the potential energy of the bob can be determined.

  • Potential energy is the energy that is stored in an object due to its position relative to some zero position. An object possesses gravitational potential energy if it is positioned at a height above (or below) the zero height. An object possesses elastic potential energy if it is at a position on an elastic medium other than the equilibrium position.

Since the gravitational potential energy of an object is directly proportional to its height above the zero position, a doubling of the height will result in a doubling of the gravitational potential energy. A tripling of the height will result in a tripling of the gravitational potential energy.

6 0
3 years ago
Other questions:
  • The number of weaving errors in a twenty-foot by ten-foot roll of carpet has a mean of 0.8 What is the probability of observing
    6·1 answer
  • If the specific surface energy for aluminum oxide is 0.90 J/m2 and its modulus of elasticity is (393 GPa), compute the critical
    11·1 answer
  • 1- A square-wave inverter has a dc source of 96 V and an output frequency of 60 Hz. The load is a series RL load with R = 5 Ohm
    7·1 answer
  • Modify the Rainfall Statistics program you wrote for Programming Challenge 2 of Chapter 7 . The program should display a list of
    15·1 answer
  • In the circuit given below, R1 = 17 kΩ, R2 = 74 kΩ, and R3 = 5 MΩ. Calculate the gain 1formula58.mml when the switch is in posit
    7·1 answer
  • Place these events in chronological order. Put the numbers 1-6 next to the<br> events.
    15·1 answer
  • Recommend the types of engineers needed to collaborate on a city project to build a skateboard park near protected wetlands.
    6·1 answer
  • Who had launched the highest number of internet satellites as of March 2020?
    14·1 answer
  • Their game off badminton is always on Tuesday
    11·1 answer
  • Which of these processes uses a die and a press to form parts?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!