subject

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

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:50, divine134
A.) generate scaffolding to create database for your application. develop all the entities identified in assignment #2. add any additional that may be identified later. b.) add data validation rules to the models that are appropriate for your application and data. c.) create links for each scaffold in the header section. part 2: application updates [30 points] a.) add two additional views to the "home" controller you created in assignment #1. b.) the two views should be named as “privacy" and "". c.) link the two newly created views in the footer section. hint: you would need to modify the “home" controller definition and create “privacy. html. erb" and “.html. erb" files in appropriate locations.
Answers: 3
image
Computers and Technology, 23.06.2019 06:30, eddsworldfrantic
You have a small company and want to keep your costs low, but it is important your employees share data. which network would provide you with the most economical solution?
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, yasarhan2
Match the following errors with their definitions. a. #name b. #value c. #ref d. 1. when a formula produces output that is too lengthy to fit in the spreadsheet cell 2. when you enter an invalid cell reference in a formula 3. when you type text in cells that accept numeric data 4. when you type in a cell reference that doesn’t exist
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, ayjahj
What can you prevent issues related to downloading content form the internet
Answers: 1
You know the right answer?
fileio – creating email addresses and life insurance payout
you have been given the assignment...

Questions in other subjects:

Konu
Biology, 28.10.2020 19:00
Konu
Mathematics, 28.10.2020 19:00