Computers and Technology

fileio – creating email addresses and life insurance payout
you have been given the assignment to create email addresses and the average life insurance payout for each beneficiary
of an employee from an input file of employees. the input and output files have every field in each record separated by a
%. the record layouts are:
for example, the records in the input file look like this:

mary%beth%jones%1%3
thomas%peter%morris%15000%2
john%quincy%smith%0%0
karl%emerson%jackson%2%4
gary%b%jones%0%0
betty%jo%nelson%1%1

the average beneficiary payout in the output file is calculated by dividing the employee’s life insurance amount by
the employee’s number of beneficiaries. if an employee has no beneficiaries (see john quincy smith and gary b. jones
above), you should avoid a “division by zero” runtime error by using a try/catch block. an exception report should be
written to the console when this occurs, and that employee’s output record should not be written.
for you to build the email address for each employee, you will need to get the company name from the console. then,
each employee’s email address will be built using the first and middle initials appended to the last name followed by an @
sign, followed by the company name and .com. all email addresses must be in lower case.
because you are working with file input, your main method statement should throw an exception. use the following
format:
public static void main(string[] args) throws exception {
}
algorithm: examples of reading data from a file and writing data to a file are found in blackboard.
1. create the file object from the file class for the output file.
2. if the file exists, put a message to the console saying file already exists and exit program (return code = 0).
3. get the domain name from the console and build the second part of the email address “@companyname. com”.
4. create a new object from the scanner class for the input file.
5. create string variables for firstname, middlename, and lastname.
6. create an output object from the printwriter class for the output file.
7. using a “while” loop and the hasnext method, split the input record into variables by using string[] tokens =
record. split("%",0); . assign the tokens into variables.
8. calculate averagebeneficiarypayout. use try/catch block for zero beneficiaries and put the exception report
info to the console.
9. build email address using substring method and then output all fields using the output. println method to the
output file.
10. after writing all output, close the output file - output.
11. print to the console that the output file was written successfully.
sample run:
enter domain name (e. g. ncc):
companyname
exception report:
input file: employeelifeinsurance. txt
first name: string
middle name: string
last name: string
life insurance amount: int
number of beneficiaries: int
output file: .txt
first name: string
middle name: string
last name: string
average beneficiary payout: int
employee email address: string
john quincy smith has zero beneficiaries and was skipped
gary b jones has zero beneficiaries and was skipped
.txt file was written successfully.
output file:
mary%beth%jones%%mbjones@companynam e. com
thomas%peter%morris%7500%tpmorris@c ompanyname. com
karl%emerson%jackson%5%kejackson@co mpanyname. com
betty%jo%nelson%1%bjnelson@companyn ame. com

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:00, mathman783
Which two editions of windows 7 support 64 bit cpus? choose two out of professional, business, starter, or home premium.
Answers: 1
image
Computers and Technology, 23.06.2019 01:10, kristofwr3444
Are special combinations of keys that tell a computer to perform a command. keypads multi-keys combinations shortcuts
Answers: 1
image
Computers and Technology, 24.06.2019 02:00, arubright177
Write an expression that will cause the following code to print "equal" if the value of sensorreading is "close enough" to targetvalue. otherwise, print "not equal". ex: if targetvalue is 0.3333 and sensorreading is (1.0/3.0), output is:
Answers: 1
image
Computers and Technology, 24.06.2019 19:20, maehardy4134
Kiesha has a worksheet with a range of cells using the following columns: name, score, group, study group, and date. kiesha needs to sort the worksheet on the date field. which option she use to most efficiently complete this task ? a use the cut and paste option to reorganize the data to fit that order b use the filter function to organize the data based on the date c use the order function to organize the data based on the date d use the sort function to organize the data based on date order
Answers: 3
Do you know the correct answer?
fileio – creating email addresses and life insurance payout
you have been given the assignment...

Questions in other subjects: