answer.
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
49. A solenoid coil with a resistance of 30 ohms and an inductance of 200 milli-henrys, is connected to a 230VAC, 50Hz supply. D
Leya [2.2K]

Answer:

69.59 ohms

Explanation:

Given that

L=200\ mH

F=50\ hZ

R=30\ ohms

For inductance

X_L=2\times \pi\times f \times LX_L\\=2\times \pi \times 50\times 200\times 10^{-3}\\=62.8\ ohm

R=30\ ohmsImpedance\\Z=\sqrt{R^2+X_L^2}\\Z=\sqrt{30^2+62.8^2}\ ohms\\Z =69.59\ ohms

8 0
2 years ago
three balls each have a mass m if a has a speed v just before a direct collision with B determine the speed of C after collision
ratelena [41]

Answer:

Vc2= V(l+e) ^2/4

Vg2= V(l-e^2)/4

Explanation:

Conservation momentum, when ball A strikes Ball B

Where,

M= Mass

V= Velocity

Ma(VA)1+ Mg(Vg)2= Ma(Va)2+ Ma(Vg)2

MV + 0= MVg2

Coefficient of restitution =

e= (Vg)2- (Va)2/(Va)1- (Vg)1

e= (Vg)2- (Va)2/ V-0

Solving equation 1 and 2 yield

(Va)2= V(l-e) /2

(Vg)2= V(l+e)/2

Conservative momentum when ball b strikes c

Mg(Vg)2+Mc(Vc)1 = Mg(Vg)3+Mc(Vc)2

=> M[V(l+e) /2] + 0 = M(Vg)3 + M(Vc) 2

Coefficient of Restitution,

e= (Vc)2 - (Vg)2/(Vg)2- (Vc)1

=> e= (Vc)2 - (Vg)2/V(l+e) /2

Solving equation 3 and 4,

Vc2= V(l+e) ^2/4

Vg2= V(l-e^2)/4

8 0
2 years ago
Read 2 more answers
A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set
iVinArrow [24]

Answer:

Functions to create a median and mode of a set of numbers

Explanation:

def median(list):

   if len(list) == 0:

       return 0

   list.sort()

   midIndex = len(list) / 2

   if len(list) % 2 == 1:

       return list[midIndex]

   else:

       return (list[midIndex] + list[midIndex - 1]) / 2

def mean(list):

   if len(list) == 0:

       return 0

   list.sort()

   total = 0

   for number in list:

       total += number

   return total / len(list)

def mode(list):

   numberDictionary = {}

   for digit in list:

       number = numberDictionary.get(digit, None)

       if number == None:

           numberDictionary[digit] = 1

       else:

           numberDictionary[digit] = number + 1

   maxValue = max(numberDictionary.values())

   modeList = []

   for key in numberDictionary:

       if numberDictionary[key] == maxValue:

           modeList.append(key)

   return modeList

def main():

   print "Mean of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: ", mean(range(1, 11))

   print "Mode of [1, 1, 1, 1, 4, 4]:", mode([1, 1, 1, 1, 4, 4])

   print "Median of [1, 2, 3, 4]:", median([1, 2, 3, 4])

main()

3 0
2 years ago
Read 2 more answers
what is the advantage of decreasing the field current of a separately excited dc motor below its nominal value
enyata [817]

Answer:

Ability to rotate at higher speeds

Explanation:

Constant K1 becomes greater than the other constant K2

This translates to that the motor being able to rotate at high speeds, without necessarily exceeding the nominal armature voltage.

The armature voltage is the voltage that is developed around the terminals of the armature winding of an Alternating Current, i.e AC or a Direct Current, i.e DC machine during the period in which it tries to generate power.

6 0
2 years ago
A cylindrical drum (2 ft. dia ,3 ft height) is filled with a fluid whose density is 40 lb/ft^3. Determine (a. the total volume o
Ksivusya [100]

Answer:

a)V=9.42\ ft^3

b)Mass in lb = 376.8 lb

Mass in slug = 11.71 slug

c)v=0.025\ ft^3/lb

d)w=1276 \ lb/ft.s^2

Explanation:

Given that

d= 2 ft

r= 1 ft

h= 3 ft

Density

\rho = 40\ lb/ft^3

a)

We know that volume V given as

V=\pi r^2 h

V=\pi \times 1^2\times 3

V=9.42\ ft^3

b)

Mass = Density x volume

mass =40\times 9.42\ lb

mass= 376.8 lb

We know that

1 lb = 0.031 slug

So 376.8 lb= 11.71 slug

Mass in lb = 376.8 lb

Mass in slug = 11.71 slug

c)

we know that specific volume(v) is the inverse of density.

v=\dfrac{1}{\rho}\ ft^3/lb

v=\dfrac{1}{40}\ ft^3/lb

v=0.025\ ft^3/lb

d)

Specific weight(w) is the product of density and the gravity(g).

w= ρ X g

w = 40 x 31.9

w=1276 \ lb/ft.s^2

8 0
2 years ago
Other questions:
  • Oil with a density of 800 kg/m3 is pumped from a pressure of 0.6 bar to a pressure of 1.4 bar, and the outlet is 3 m above the i
    9·1 answer
  • A closed system consisting of 4 lb of a gas undergoes a process during which the relation between pressure and volume is pVn 5 c
    7·1 answer
  • Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per li
    15·1 answer
  • Given a 5x5 matrix for Playfair cipher a. How many possible keys does the Playfair cipher have? Ignore the fact that some keys m
    6·1 answer
  • You want to determine whether the race of the defendant has an impact on jury verdicts. You assign participants to watch a trial
    9·1 answer
  • 10. Aluminum-lithium (Al-Li) alloys have been developed by the aircraft industry to reduce the weight and improve the performanc
    7·1 answer
  • A pipe is insulated such that the outer radius of the insulation is less than the critical radius. Now the insulation is taken o
    11·1 answer
  • An equation used to evaluate vacuum filtration is Q = ΔpA2 α(VRw + ARf) , Where Q ≐ L3/T is the filtrate volume flow rate, Δp ≐
    13·1 answer
  • Select the level of education that is best demonstrated in each example.
    10·2 answers
  • Who can work on a fixed ladder that extends more than 24 feet?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!