Write a program that reads in the file

Assignment Help JAVA Programming
Reference no: EM13768839

You are given a file containing the names and addresses of company employees from many years ago that your manager has asked you to import into a database. You can use a CSV file and your database application to load the file, but the file your manager gave you was exported from an old, non-standard accounting system. Here is its format:

Freddy | Kruger
1313 | MockingBird|Lane
Houston | Texas
Billy | Thornton
1010 | Slingblade|Street
Houston| Texas

Write a program that reads in the file and exports it to a standard CSV format. For the records above, the output format would be Freddy Kruger, 1313 Mockingbird Lane, Houston, Texas Billy Thornton, 1010 Slingblade Street, Houston, Texas

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class InClassExercisee {

public static void main(String[] args) throws IOException {

Scanner inputfile = new Scanner(new File("data.csv"));
while (inputfile.hasNextLine()) {
String scan1 = inputfile.next();
scan1 = scan1.replaceAll("[\\| ]", " ");
String[] parts = inputfile.nextLine().split("|", 2);
for (String p : parts) {
System.out.println(p);
}
scan1 = scan1.replaceAll("[\\| ]", " ");
String scan2 = inputfile.next();
scan2 = scan2.replaceAll("[\\|]", " ");
String scan3 = inputfile.next();
scan3 = scan3.replaceAll("[\\| ]", ", ");
System.out.println(scan1 + "," + scan2 + ","
+ scan3 + inputfile.nextLine());
}
}
}

OUTPUT FOR THE PROGRAM ABOVE is:

Fred Flintstone,1212 Bedrock,Austin, Texas

Harry Potter,1234 Hogwarts,Road

Somewhere Overthere,Ugmal Smith,111, On the Sea

London England,Udlal Hayes,0000, Firston, Block

Harrison Alabama,Bifund Frediburg,1, Small Street

Shire

Hobbiton The,Zaghim Zagg,A-1, Another Street

Wormwood Mordor,Kari Underwood,1234, Song Street

Nashville Tennessee,Fari Away,A323, Desire

Houston Texas,Thudu Ofthewood,555, NotANumberedStreet Street

Snook Texas,Gimli Axthrower,123, Dairy Lane

Lonely Mountain|England

The,Throri Mybrother,8088, Java Lane

Exception in thread "main" java.util.NoSuchElementException

at java.util.Scanner.throwFor(Unknown Source)

at java.util.Scanner.next(Unknown Source)

at InClassExercisee.main(InClassExercisee.java:22)

BUT I WANTED IT TO LOOK LIKE THIS:

Fred Flintstone,1212 Bedrock,Austin, Texas

Harry Potter,1234 Hogwarts,Road, Somewhere, Overthere

Ugmal Smith,111 On the Sea, London, England

Udlal Hayes, 0000 Firston, Block, Harrison, Alabama

Reference no: EM13768839

Questions Cloud

Formulate a plan to relate the primary legal ramifications : Formulate a plan to relate the primary legal ramifications to the professional staff regarding ethical treatment of the hospital's HIV / AIDS patients
Maximum rate of growth a corporation can achieve : Which one of the following will increase the maximum rate of growth a corporation can achieve?
What percent of preferred stock dividend will be taxable : What is the value of this firm in its current all-equity state. What will the firm's value be after the recapitalization and what percent of the preferred stock dividend will be taxable, according to the U.S. tax code?
Size of the monthly payments he will be required to make : Joe secured a loan of $10,000 two years ago from a bank for use toward his college expenses. The bank charges interest at the rate of 4%/year compounded monthly on his loan. Now that he has graduated from college, Joe wishes to repay the loan by amor..
Write a program that reads in the file : Write a program that reads in the file and exports it to a standard CSV format. For the records above, the output format would be Freddy Kruger, 1313 Mockingbird Lane, Houston, Texas Billy Thornton, 1010 Slingblade Street, Houston, Texas
What about dna fingerprinting explain : What about DNA fingerprinting? Explain. How do you feel about the outcomes of these cases? Explai
Issues related to childeren activities : What are some policies and procedures that need to be followed when planning and having field trips?
What is the net present value of the project : Ford Motors expects a new hybrid-engine project to produce incremental cash flows of $100 million each year and expects these to grow at 4% each year. The upfront project costs are $900 million and Ford's weighted average cost of capital is 9%. If th..
What is the effect on the terms of the contract : A trader has a put option contract to sell 100 shares of a stock for a strike price of $650. What is the effect on the terms of the contract of:

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd