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

  Describe a multidimensional array

Describe a multidimensional array for a summer camp, the first array would be the number of kids say 30, then it would break them up by ages 6-9 (4 different groups) and lastly by sex m or f.

  Implement bounded partial queue by using signaling mechanism

Implement the same using a signaling mechanism that signals to all waiting dequeuers and do a performance comparison using timing analysis. Which works faster?

  Develop java package comprising of class using encapsulation

Develop the Java package comprising of Class and Student with the given requirements. Encapsulation, Method to print student details alone.

  Create a class named student that has three member variables

Create a class named Student that has three member variables

  Build an android application to execute some of the queries

Build an android application to execute some of the queries -

  Java program editing

Prompt the user for the student's score and put that value into an object

  Create a user interface for a library application

Create a user interface for a library application that allows the user (i.e., the Librarian) to enter Book objects.

  The calculator should display the amount of commission

The calculator should display the amount of commission (in dollars), based on the amount of sales entered and the commission rate selected and the total annual compensation.

  Prepare a program that constructs a binary tree

Write your own implementation of primitive operations and use self-referential classes in your implementation.

  Build the gui layout of the game

Build the Build the GUI layout of the game in java.

  Create a 2-by-3 two-dimensional array of integers

Create a 2-by-3 two-dimensional array of integers and fill it with data. Loop through the array and locate the smallest value stored.

  Implement a sorting algorithm for inclusion in a package

Prepare a targeted plan in which you present your detailed strategies to recruit and select 20 Engineers to hire (full-time or part-time) within 8 months - Implement a sorting algorithm for inclusion in a package for a lucrative client.

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