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
Water is flowing at a rate of 0.15 ft3/s in a 6 inch diameter pipe. The water then goes through a sudden contraction to a 2 inch
Georgia [21]

Answer:

Head loss=0.00366 ft

Explanation:

Given :Water flow rate Q=0.15 \frac{ft^{3}}{sec}

         D_{1}= 6 inch=0.5 ft

        D_{2}=2 inch=0.1667 ft

As we know that Q=AV

A_{1}\times V_{1}=A_{2}\times V_{2}

So V_{2}=\frac{Q}{A_2}

     V_{2}=\dfrac{.015}{\frac{3.14}{4}\times 0.1667^{2}}

     V_{2=0.687 ft/sec

We know that Head loss due to sudden contraction

           h_{l}=K\frac{V_{2}^2}{2g}

If nothing is given then take K=0.5

So head lossh_{l}=(0.5)\frac{{0.687}^2}{2\times 32.18}

                                    =0.00366 ft

So head loss=0.00366 ft

4 0
2 years ago
Which of these fuel injection systems operates with fuel injectors located only in the intake manifold near each intake
Stella [2.4K]

Answer:

C. Multipoint fuel injection

Explanation:

A fuel injection system can be defined as a system found in the engine of most automobile cars, used for the supply of a precise amount of fuel or fuel-air mixture to the cylinders in an internal combustion engine through the use of an injector.

There are different types of fuel injection system and these includes;

I. Central-point injection.

II. Throttle (single point) body injection.

III. Gasoline direct injection.

IV. Multipoint (port) fuel injection.

Multipoint fuel injection is a type of fuel injection system that operates with fuel injectors located only in the intake manifold near each intake valve and sprays fuel toward the valve. As a result, it allows for the supply of a precise amount of fuel and as such creating a better air-fuel ratio for automobile cars.

8 0
2 years ago
What is made in heaven?​
kramer

Answer:

Babies come from heaven didn't you know?

3 0
2 years ago
Illustrate the crowbar protection for silicon controlled rectifier​
julsineya [31]

Answer:

The SCR over voltage crowbar or protection circuit is connected between the output of the power supply and ground. ... It also clamps the gate voltage at ground potential until the Zener turns on. The capacitor C1 is present to ensure that short spikes to not trigger the circuit.

4 0
2 years ago
The power supply converts the wall outlet AC power into DC power. T or F
Alika [10]

Answer:

True

Explanation:

All computer parts require DC power to operate, and wall outlets provide AC Power.

7 0
3 years ago
Other questions:
  • What is productivity as it relates to labor?
    11·1 answer
  • declare integer product declare integer number product = 0 do while product &lt; 100 display ""Type your number"" input number p
    8·1 answer
  • The truck travels in a circular path having a radius of 50 m at a speed of v = 4 m&gt;s. For a short distance from s = 0, its sp
    11·1 answer
  • Write a function called arraySum() that takes two arguments: an integer array and the number of elements in the array. Have the
    14·1 answer
  • A plot of land is an irregular trangle with a base of 122 feet and a height of 47 feet what is the area of the plot?
    13·1 answer
  • You rent an apartment that costs $1800 per month during the first year, but the rent is set to go up 11,5% per year. What would
    12·1 answer
  • A wooden pallet carrying 540kg rests on a wooden floor. (a) a forklift driver decides to push it without lifting it.what force m
    8·1 answer
  • In order to avoid a rollover, what is the highest degree incline one should mow on? 10-degree incline 5-degree incline 30-degree
    15·1 answer
  • The inspector should inspect insulation in unfinished spaces, including attics, _____ and foundation areas.
    13·1 answer
  • Which option distinguishes why the behaviors of the team in the following scenario are so important during the engineering desig
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!