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
Wastewater flows into a _________ once it is released into a floor drain.
vodomira [7]

Answer:

a

Explanation:

5 0
3 years ago
A car has a steering wheel with a 15 inch diameter that takes 18 lbs of Effort force to move is
elena-14-01-66 [18.8K]

Answer: A first class lever in static equilibrium has a 50lb resistance force and 15lb effort force. The lever's effort force is located 4 ft from the fulcrum.

Explanation:

4 0
2 years ago
The 15-kg block A slides on the surface for which µk = 0.3. The block has a velocity v = 10 m/s when it is s = 4 m from the 10-k
sammy [17]

Answer:

s_max = 0.8394m

Explanation:

From equilibrium of block, N = W = mg

Frictional force = μ_k•N = μ_k•mg

Since μ_k = 0.3,then F = 0.3mg

To determine the velocity of Block A just before collision, let's apply the principle of work and energy;

T1 + ΣU_1-2 = T2

So, (1/2)m_a•(v_ao)² - F•s =(1/2)m_a•(v_a1)²

Plugging in the relevant values to get ;

(1/2)•(15)•(10)² - (0.3•15•9.81•4) =(1/2)(15)•(v_a1)²

750 - 176.58 = 7.5(v_a1)²

v_a1 = 8.744 m/s

Using law of conservation of momentum;

Σ(m1v1) = Σ(m2v2)

Thus,

m_a•v_a1 + m_b•v_b1 = m_a•v_a2 + m_b•v_b2

Thus;

15(8.744) + 10(0) = 15(v_a2) + 10(v_b2)

Divide through by 5;

3(8.744) + 2(0) = 3(v_a2) + 2(v_b2)

Thus,

3(v_a2) + 2(v_b2) = 26.232 - - - (eq1)

Coefficient of restitution has a formula;

e = (v_b2 - v_a2)/(v_a1 - v_b1)

From the question, e = 0.6.

Thus;

0.6 = (v_b2 - v_a2)/(8.744 - 0)

0.6 x 8.744 = (v_b2 - v_a2)

(v_b2 - v_a2) = 5.246 - - - (eq2)

Solving eq(1) and 2 simultaneously, we have;

v_b2 = 8.394 m/s

v_a2 = 3.148 m/s

Now, to find maximum compression, let's apply conservation of energy on block B;

T1 + V1 = T2 + V2

Thus,

(1/2)m_b•(v_b2)² + (1/2)k(s_1)² = (1/2)m_b•(v_b'2)² + (1/2)k(s_max)²

(1/2)10•(8.394)² + (1/2)1000(0)² = (1/2)10•(0)² + (1/2)(1000)(s_max)²

500(s_max)² = 352.29618

(s_max)² = 352.29618/500

(s_max)² = 0.7046

s_max = 0.8394m

8 0
3 years ago
A 4-pole, 3-phase induction motor operates from a supply whose frequency is 60 Hz. calculate: 1- the speed at which the magnetic
DiKsa [7]

Answer:

The answer is below

Explanation:

1) The synchronous speed of an induction motor is the speed of the magnetic field of the stator. It is given by:

n_s=\frac{120f_s}{p}\\ Where\ p\ is \ the \ number\ of\ machine\ pole, f_s\ is\ the\ supply \ frequency\\and\ n_s\ is \ the \ synchronous\ speed(speed \ of\ stator\ magnetic \ field)\\Given: f_s=60\ Hz, p=4. Therefore\\\\n_s=\frac{120*60}{4}=1800\ rpm

2) The speed of the rotor is the motor speed. The slip is given by:

Slip=\frac{n_s-n_m}{n_s}. \\ n_m\ is\ the \ motor\ speed(rotor\ speed)\\Slip = 0.05, n_s= 1800\ rpm\\ \\0.05=\frac{1800-n_m}{1800}\\\\ 1800-n_m=90\\\\n_m=1800-90=1710\ rpm

3) The frequency of the rotor is given as:

f_r=slip*f_s\\f_r=0.04*60=2.4\ Hz

4) At standstill, the speed of the motor is 0, therefore the slip is 1.

The frequency of the rotor is given as:

f_r=slip*f_s\\f_r=1*60=60\ Hz

6 0
3 years ago
The vertical and horizontal poles at the traffic-light assembly are erected first. Determine the additional force and moment rea
konstantin123 [22]

Answer:

1. Az=258 lb

2. My=3440 ft lb

3. ∑Mz= 0

Explanation:

∑ Fx= Ax=0

∑ Fy= Ay=0

∑ Fz= Az-86-86-86

Az=258 lb

∑Mx=86 X 31 +Mx=0

Mx=2666 ft lb

∑My=86 X 40 +My=0

My=3440 ft lb

∑Mz= 0

6 0
3 years ago
Other questions:
  • Twenty-five wooden beams were ordered or a construction project. The sample mean and he sample standard deviation were measured
    6·1 answer
  • For a given set of input values, a NAND gate produces the opposite output as an OR gate with inverted inputs.A. True
    7·1 answer
  • Determine the combined moment about O due to the weight of the mailbox and the cross member AB. The mailbox weighs 3.2 lb and th
    14·1 answer
  • 0.9 lbm of water fills a container whose volume is 1.9 ft3. The pressure in the container is 100 psia. Calculate the total inter
    9·1 answer
  • With a brief description, What are the 14 principles of management by fayol.​
    10·1 answer
  • What structure was created to help prevent shipwrecks?
    9·1 answer
  • An Otto cycle with air as the working fluid has a compression ratio of 8.2. Under cold air standard conditions, what is the ther
    14·1 answer
  • The heat transfer surface area of a fin is equal to the sum of all surfaces of the fin exposed to the surrounding medium, includ
    6·1 answer
  • What is the difference between POP3 and IMAP?
    5·1 answer
  • Which one of the following best defines hardness: (a) energy absorbed by a material when an object strikes its surface, (b) resi
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!