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]
2 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]2 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
Un mol de gas ideal realiza un trabajo de 3000 J sobre su entorno, cuando se expande de manera isotermica a una temperatura de 5
Shkiper50 [21]

Answer:

74,4 litros

Explanation:

Dado que

W = nRT ln (Vf / Vi)

W = 3000J

R = 8,314 JK-1mol-1

T = 58 + 273 = 331 K

Vf = desconocido

Vi = 25 L

W / nRT = ln (Vf / Vi)

W / nRT = 2.303 log (Vf / Vi)

W / nRT * 1 / 2.303 = log (Vf / Vi)

Vf / Vi = Antilog (W / nRT * 1 / 2.303)

Vf = Antilog (W / nRT * 1 / 2.303) * Vi

Vf = Antilog (3000/1 * 8,314 * 331 * 1 / 2,303) * 25

Vf = 74,4 litros

3 0
3 years ago
A 100 meter dash is run on a track in the direction of the vector = 2 + 7 . The wind velocity is = 5 + km/hr. The rules say that
Scrat [10]

Answer:joe mamma

Explanation:

6 0
2 years ago
The maximum voltage in a cooling system should not exceed ______ volts.
Natali [406]

Answer:2%

When the voltages between the three phases are not equal, the current increases dramatically in the motor winding's, and if allowed to continue, the motor will be damaged.

Explanation:

7 0
1 year ago
Acertain foundation will experience a bearing capacity failurewhen it is subjected to a downward load of 2200 kN. Using ASD with
ehidna [41]

Answer:

Um...

Explanation:

This is what I like to see teachers giving out.

7 0
2 years ago
Based on experimental observations, the acceleration of a particle is defined by the relationa = -( 0.1 + sin(x/b) ),where a and
yKpoI14uk [10]

Answer:

a) v = +/- 0.323 m/s

b) x = -0.080134 m

c) v = +/- 1.004 m/s

Explanation:

Given:

                             a = - (0.1 + sin(x/b))

b = 0.8

v = 1 m/s @ x = 0

Find:

(a) the velocity of the particle when x = -1 m

(b) the position where the velocity is maximum

(c) the maximum velocity.

Solution:

- We will compute the velocity by integrating a by dt.

                           a = v*dv / dx =  - (0.1 + sin(x/0.8))

- Separate variables:

                           v*dv = - (0.1 + sin(x/0.8)) . dx

-Integrate from v = 1 m/s @ x = 0:

                          0.5(v^2) = - (0.1x - 0.8cos(x/0.8)) - 0.8 + 0.5

                          0.5v^2 =  0.8cos(x/0.8) - 0.1x - 0.3

- Evaluate @ x = -1

                          0.5v^2 = 0.8 cos(-1/0.8) + 0.1 -0.3

                          v = sqrt (0.104516)

                          v = +/- 0.323 m/s

- v = v_max when a = 0:

                           -0.1 = sin(x/0.8)

                             x = -0.8*0.1002

                             x = -0.080134 m

- Hence,

                            v^2 = 1.6 cos(-0.080134/0.8) -0.6 -0.2*-0.080134

                            v = sqrt (0.504)

                            v = +/- 1.004 m/s

4 0
3 years ago
Other questions:
  • Write a iterative function that finds the n-th integer of the Fibonacci sequence. Then build a minimal program (main function) t
    15·2 answers
  • In what situation you would prefer to use a successive approximation ADC over flash ADC?
    13·1 answer
  • An electrochemical cell is composed of pure nickel and pure iron electrodes immersed in solutions of their divalent ions. If the
    13·1 answer
  • How do you put air knight in slingshock mode.
    9·1 answer
  • Consider a very long, cylindrical fin. The temperature of the fin at the tip and base are 25 °C and 50 °C, respectively. The dia
    11·1 answer
  • What is meant by the thickness to chord ratio of an aerofoil?
    12·1 answer
  • If most wildfires are suppressed (all fires are put out) for many years, how does the risk of wildfire in the area change in the
    10·1 answer
  • When did michael faraday invent wind powered electrical generation?
    11·1 answer
  • What invention of the Middle Ages contributed to making books easily available?
    15·1 answer
  • Led test lights are used to test circuits that include controllers and computers. True or false
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!