Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the file that should be read is .txt type and looks exactly like this with spaces Cheryl Adams Tennessee Williams Isaac Asimov Lincoln Orson Scott

image text in transcribed

image text in transcribed

the file that should be read is .txt type and looks exactly like this with spaces

Cheryl Adams Tennessee Williams Isaac Asimov Lincoln Orson Scott Card

Module 15 Lab: File Input/Output Lab Objective The objective of this assignment is to learn how to read and write from files for storing text information Lab Description Write a program called 'Names', which does the following: You are given a text file that contains the names of people. Every name in the file consists of a first name followed by a last name. Somehow the file got corrupted and the format of the names got mixed up Your program will read the given file Namesin.txt for input, but prompt the user for the desired output file name (i.e., NamesOut.txt) Your program will read in the names from the input file and write them back to the output file ensuring that each line contains a single last name, followed by a comma and a single first name Your program will also append an identifier preceding the name in the file For example, if the input file contains Cheryl Adam Williams Lincolrn Scott Tennessee I saac Asimov Orson Card The output file should be 1. Adams, Cheryl 2. Williams, Tennessee 3. Asimov, Isaac 4. Orso 5. Card, Scott n, Lincoln Lab Instructions Create a new Java Application called Names. This lab template file can be found on Canvas Assign inputFile variable to Input File using new File Prompt for Desired Output Filename, read into outputName Strin C Within a try block, create a new outputFile object, using PrintWriter, create a new filelnput object, using Scanner to point to inputFile Within a catch block, catch the FileNotFoundException to properly display any error and exit the application Create a for loop to read in names from the input file Within a try block read in the names from the input file D Read in the first String to firstName array. Read in the second String to the lastName array. Print out the firstName, lastName combination to verify that they are read properly Increment the entries count to identify how many full names have been read in The display output should be formatted as: Cheryl Adams Tennessee Williams Isaac Asimov Lincoln Orson Scott Card

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions