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

  What is the purpose of the restrict keyword in c99

Arrays of strings in C and C++ can also be initialized with string literals. In this case, the array is one of pointers to characters.

  Techniques used to secure web servers

Two of the most popular web servers are Apache and Microsoft IIS. Discuss some of the tools and techniques used to secure these web servers.

  What are the benefits of documenting

What are the benefits of documenting our programs in Java?

  A method with the signature public static void

A method with the signature public static void printDetails(City[] cities) that will iterate through the cities and printthe details of the city using the displayDetails(...) method.

  Videorental store operatorrecord clients

Project is to design a program to help a videorental store operatorrecord clients' transactions - Design a primitive database indicating

  Prepare a demo program

Design, and implement a class that will be used in a program that simulates a combination lock. The lock has a circular knob with the numbers 0 through 39 marked on the edge, and it has a three-number combination, which we will call x,y,z.

  Strong authentication can also risk availability

Strong authentication can also risk availability. A simple example is that forgetting your password denies you access to that which required a password. Sometimes the stakes are high, for example, if a network administrator is the only one who knows ..

  Implement a personal scheduler windows application

Implement a personal scheduler Windows application - Entries can be enabled and disabled: Enabled schedule entries appear dark in the main window, and disabled entries appear grayed out in the list.

  Determines and displays the smallest and largest

Create a method that determines and displays the smallest and largest of the ten values. Then, pass the array to the method - Create a GUI application whose button's Click() method accepts ten integer values from a TextBox and stores them in an arra..

  Implement simple java program to input syllabus grades

To implement simple Java program to input (hypothetical) syllabus grades, computing and displaying both normal Mean and Harmonic Mean.

  Prepare a simple windows calculator in java it must have a

create a simple windows calculator in java. it should have a labeled text field for the user to provide input as well

  What secret does soraya tell amir

What secret does soraya tell amir and how does amir react to this information

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