A table of data from a text file

Assignment Help Basic Computer Science
Reference no: EM13881321

In this lab you will write a program to read in a table of data from a text file where each line represents a record, and manipulate it. Each line of the input file will consist of sequence of quoted strings (using double quotation marks) separated by commas.Each quoted string will not contain any double quotation marks.Each line will contain the same number of quoted strings as any other.Here is a useful test file containing such data.

"1997","Ford","E350","ac, abs, moon","3000.00"
"1999","Chevy","Venture Extended Edition","","4900.00"
"1999","Chevy","Venture Extended Edition, Very Large","","5000.00"
"1996","Jeep","Grand Cherokee","MUST SELL! air, moon roof, loaded","4799.00"

Step 1. In a file Text1.java write the class Text1, a main method and a method with the following signature.

private static String[] read_record(Scanner in)

Don't forget theimportdirective for the Scanner class at the top of your program.

This method should read a line of text from the Scanner if there is one. (If there is no line to be read it should returnnull.) Then it should create String objects corresponding to the text inside each quoted string in that line, and return a new array of Strings containing these in the order they occurred on the line. The array returned should be of exactly the right size. You may assume that there are fewer than 1000 such quoted strings on a line.

Test your method by writing a loop in the main program to write the strings one-per-line in the array returned by a single call toread_record.

You need to be careful that some of the quoted strings may themselves contain white space, so merely replacing the double quotation marks and the commas with a white space character and then breaking up the line into tokens will not work. The quoted strings may also contain commas, so similar remarks apply for those. You may find methods in the String class to be useful. Do not use any other classes that come with Java apart from those taught in this course.

Step 2.Copy Text1.java to Text2.java and rename the class Test1 to Test2. Now modify your program to receive an input filename and an output filenameon the command lineused to execute Text2.java, and open them for input and output. Write a method with the following signature.

private static String entab_record(String[] rec)This method should produce a String consisting of the strings in the array rec concatenated together with a tab character between each string and the following one. Ensure that there is no trailing tab after the last string to come from the array. (Tabs are to be used here in the same way that commas were used in the original input, to separate the items of data on a line, only now the data must not be quoted.)

Now write a main program to read each line withread_recordand convert the resulting array into a String withentab_record, and then write it out followed by a newline, so that the result of running your program is to convert the original file to one containing the same data on each line, just formatted with tabs separating the data instead of quoted with commas separating the data.

Reference no: EM13881321

Questions Cloud

Did most of the financing for assets come from creditors : Complete the following balance sheet at December 31, 2014. Using the retained earnings equation and an opening balance of $ 0, work backwards to compute the amount of net income for the year ended December 31, 2014. As of December 31, 2014, did most ..
What do you feel are the most important qualities : What do you feel are the most important qualities that a manager must possess to be effective? What do you feel are the most important qualities for a leader to possess to be effective
Which method do you use to estimate the identi?ed equations : Using the order condition of identi?cation, determine which of the four equations are identi?ed, either exact or over.
How might the organization use technology to improve perform : How might the organization use technology to improve performance and quality?
A table of data from a text file : In this lab you will write a program to read in a table of data from a text file where each line represents a record, and manipulate it. Each line of the input file will consist of sequence of quoted strings (using double quotation marks) separated b..
Determining an organizations goals : What factors should you consider in determining an organization's goals? How would you decide which strategic and operational plans to use to achieve your goals
Identify an appropriate label for each item : Identify an appropriate label (account name) for each item as it would be reported in the company's financial statements. Choose from the following: Accounts Payable, Accounts Receivable, Cash, Common Stock, Dividends, Land, Notes Payable, Sales Reve..
Program needs to be in pseudocode : Need help Designing a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and..
What is the companys target debt-equity ratio : Fama’s Llamas has a weighted average cost of capital of 11 percent. The company’s cost of equity is 13 percent, and its pretax cost of debt is 9 percent. The tax rate is 40 percent. What is the company’s target debt−equity ratio?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Who developed the ibm pc

What is the code name for the 12 engineers who developed the IBM PC and In which year did Amazon.com report that for the first time sales of e-books exceeded the sales of hardcover books?

  What cost cutting measures are proposed

What cost cutting measures are proposed and How will the expanded coverage be paid for?

  Access control system

What access control system is most valuable for protecting enterprise systems? Why? What are two specific strengths and two specific drawbacks for your chosen access control system?

  Fully web-based access for both general public and secretary

Fully web-based access for both general public and Secretary of state employees a database of drivers and their personnel information contained on their drivers licenses

  Explain most likely causes for failed technology projects

Discuss the three (3) most likely causes for failed technology projects.

  Successful at attracting and keeping purchasing customers

Successful at attracting and keeping purchasing customers

  Gui library to convert celsius to fahrenheit

Write a program in Java using Swing GUI library to convert Celsius to Fahrenheit. If the input is in Celsius, the program can output equivalent Fahrenheit. Both the input and output should use Swing GUI program. Both the input and output should use S..

  Design program that creates object productionworkers

Design an Employee class that has fields for the following pieces of information: Employee Name Employee Number Next, design a class named ProductionWorker that extends the Employee class

  Write code that merges two sorted arrays

Write a code that merges two sorted arrays so that the result is a sorted array. In your code, declare an array called ‘A1’ of size 5 and an array ‘A2’ of size 5. Fill them with numbers that are in ascending order.

  How would the physical security aspect of protecting compute

How would the physical security aspect of protecting computer assets relate in this case? Make sure to give some examples.

  Logical data-base structure

A report generator is used to. Which of the following is not a logical data-base structure?

  Currently using common data exchange and data management

•Identify at least two (2) industries that are currently using common data exchange and data management trends. Rank the success of each implementation based on the ease of implementation, ease of use, and costs.

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