Question
Java Your boss has just put you in charge of updating the company's client contact list. This file contains records in the following format: id,first_name,last_name,email
Java Your boss has just put you in charge of updating the company's client contact list.
This file contains records in the following format: id,first_name,last_name,email
1,Norry,Killby,nkillby0@photobucket.com
Your job is to reformat each record as follows:
last_name, first_name, email
Killby, Norry,
Starter Code:
package contactlistupdater;
import java.io.FileNotFoundException;
import java.io.IOException; import java.nio.file.Paths; import java.util.Formatter; import java.util.Scanner; import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class ContactListUpdater { private static final String INPUT_FILENAME = "contacts.txt"; private static final String OUTPUT_FILENAME = "updated-contacts.txt"; /** * Transforms a String containing a contact entry to a new format */ public static String processContactEntry(String input) { // TODO your code here... return input; } public static void main(String[] args) { // Open input/output files and process line by line try (Formatter output = new Formatter(OUTPUT_FILENAME)) { try (Scanner input = new Scanner(Paths.get(INPUT_FILENAME))) { // Process each line while (input.hasNextLine()) { output.format("%s%n", processContactEntry(input.nextLine())); } } catch (IOException ex) { System.err.println("Unable to open input file: " + INPUT_FILENAME); ex.printStackTrace(); } } catch (FileNotFoundException ex) { System.err.println("Unable to open output file: " + OUTPUT_FILENAME); ex.printStackTrace(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started