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 0.9% solution of NaCl is considered isotonic to mammalian cells. what molar concentration is this?
natka813 [3]

Answer:

58.44 g/mol The Molarity of this concentration is 0.154 molar

Explanation:

the molar mass of NaCl is 58.44 g/mol,

0.9 % is the same thing as 0.9g of NaCl , so this means that 100 ml's of physiological saline contains 0.9 g of NaCl.  One liter of physiological saline must contain 9 g of NaCl.  We can determine the molarity of a physiological saline solution by dividing 9 g by 58 g... since we have 9 g of NaCl in a liter of physiological saline, but we have 58 grams of NaCl in a mole of NaCl.  When we divide 9 g by 58 g, we find that physiological saline contains 0.154 moles of NaCl per liter.  That means that physiological saline (0.9% NaCl) has a molarity of 0.154 molar.  We can either express this as 0.154 M or 154 millimolar (154 mM).

3 0
4 years ago
When framing a building, a simple way to estimate the total amount of wall studs needed is to allow
Levart [38]
1+1=2
Solution
3:932(2)=61
4 0
3 years ago
A battery with an f.e.m. of 12 V and negligible internal resistance is connected to a resistor of 545 How much energy is dissipa
Alenkasestr [34]

Answer:

When are resistors in series? Resistors are in series whenever the flow of charge, called the current, must flow through devices sequentially. For example, if current flows through a person holding a screwdriver and into the Earth, then  

R

1

 in Figure 1(a) could be the resistance of the screwdriver’s shaft,  

R

2

 the resistance of its handle,  

R

3

 the person’s body resistance, and  

R

4

 the resistance of her shoes.

Figure 2 shows resistors in series connected to a voltage source. It seems reasonable that the total resistance is the sum of the individual resistances, considering that the current has to pass through each resistor in sequence. (This fact would be an advantage to a person wishing to avoid an electrical shock, who could reduce the current by wearing high-resistance rubber-soled shoes. It could be a disadvantage if one of the resistances were a faulty high-resistance cord to an appliance that would reduce the operating current.)

Two electrical circuits are compared. The first one has three resistors, R sub one, R sub two, and R sub three, connected in series with a voltage source V to form a closed circuit. The first circuit is equivalent to the second circuit, which has a single resistor R sub s connected to a voltage source V. Both circuits carry a current I, which starts from the positive end of the voltage source and moves in a clockwise direction around the circuit.

Figure 2. Three resistors connected in series to a battery (left) and the equivalent single or series resistance (right).

To verify that resistances in series do indeed add, let us consider the loss of electrical power, called a voltage drop, in each resistor in Figure 2.

According to Ohm’s law, the voltage drop,  

V

, across a resistor when a current flows through it is calculated using the equation  

V

=

I

R

, where  

I

 equals the current in amps (A) and  

R

 is the resistance in ohms  

(

Ω

)

. Another way to think of this is that  

V

 is the voltage necessary to make a current  

I

 flow through a resistance  

R

.

So the voltage drop across  

R

1

 is  

V

1

=

I

R

1

, that across  

R

2

 is  

V

2

=

I

R

2

, and that across  

R

3

 is  

V

3

=

I

R

3

. The sum of these voltages equals the voltage output of the source; that is,

V

=

V

1

+

V

2

+

V

3

.

 

This equation is based on the conservation of energy and conservation of charge. Electrical potential energy can be described by the equation  

P

E

=

q

V

, where  

q

 is the electric charge and  

V

 is the voltage. Thus the energy supplied by the source is  

q

V

, while that dissipated by the resistors is

q

V

1

+

q

V

2

+

q

V

3

.

Explanation:

8 0
3 years ago
Please help I need it by today!!!
AfilCa [17]

Answer:

if engineering disappeared for a day i would be at a loss. i wouldnt know what to do with myself considering engineering is my life. one way that engineers improve my life is they help me to understand enything end everything

Explanation:

7 0
3 years ago
Meaning of temporary stitches​
algol13

Answer:

They are use to hold garment or fabric pieces together before pernament stitches are made

6 0
3 years ago
Read 2 more answers
Other questions:
  • A six-lane freeway (three lanes in each direction) currently operates at maximum LOS C conditions. The lanes are 11 ft wide, the
    5·1 answer
  • The steel bar has a 20 x 10 mm rectangular cross section and is welded along section a-a. The weld material has a tensile yield
    11·1 answer
  • Pehdhdjdjdodnjdndjdjdjfjdk
    11·2 answers
  • The rainfall rate in a certain city is 20 inches per year over an infiltration area that covers 33000 acres. Twenty percent of t
    6·1 answer
  • The guy wires AB and AC are attached to the top of the transmission tower. The tension in cable AB is 8.7 kN. Determine the requ
    8·1 answer
  • 1. Using the formula above, complete this task.
    9·1 answer
  • How can you drop two eggs the feweHow can you drop two eggs the fewest amount of times, without them breaking? ...st amount of t
    13·2 answers
  • Is the science of measurement
    13·2 answers
  • It is possible to design a reactor where the scy conductor and the nitrogen/ammonia electrode operate at different temperatures.
    12·1 answer
  • This test should be performed on all cord sets, receptacles that aren't part of a building or structure's permanent wiring, and
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!