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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:40
In the lab, which of the following displayed a list of all installed services and included a description of the service, the current state, and whether the service started automatically or manually? a. the services manager b. the applications summary c. the recommended services d. list the safe services list
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Write the html code to make a link out of the text “all about puppies”. it should link to a pdf called “puppies.pdf” inside the “documents” folder. the pdf should open in a new window.
Answers: 2
question
Computers and Technology, 23.06.2019 17:30
Write pseudocode to represent the logic of a program that allows the user to enter a value. the program multiplies the value by 10 and outputs the result.
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
What multimedia system creates an immersive, real-life experience that the user can interact with?
Answers: 1
You know the right answer?
fileio – creating email addresses and life insurance payout
you have been given the assignment...
Questions
question
Chemistry, 04.06.2021 19:00
question
Mathematics, 04.06.2021 19:00
question
Mathematics, 04.06.2021 19:00
question
Mathematics, 04.06.2021 19:00
question
Mathematics, 04.06.2021 19:00
question
History, 04.06.2021 19:00
question
Biology, 04.06.2021 19:00
question
Mathematics, 04.06.2021 19:00
Questions on the website: 13722360