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

  Explain components of information systems

Using the three components of information systems and the complementary assets concepts, discuss why some companies achieve better results with information systems than others.

  Program that reads expressions over binary operators

Write a program that reads expressions over binary operators +, -, *, /, ^ and parenthesis from the standard input and displays the result of evaluating the input expression to the standard output. The program must first read the priorities and as..

  How to identify duties of the lab employees

Assume that you decide to set up a computer forensics laboratory. Submit a planning report for your lab with the following components.

  How many bits must the mar register have

Assume you have 512MB of main memory. How many bits must the MAR register have? Show your work.

  Main attributes of product in plug-ins change process

What are some main attributes of product and how may it help operations of organization? How do third-party plug-ins change process of diagnosing and troubleshooting errors in application?

  Code around in a file to add joptionpane

It requires us to change some code around in a file to add joptionpane dialog boxes in instead of the fields already there. The following is the exact wording of the assignment:

  Write the code to compute s on the basis of these values

In physics, a common useful equation for finding the position s of a body in linear motion at a given time t, based on its initial position s0, initial velocity v0, and rate of acceleration a, is the following:

  Shown that moore law not only apply to semiconductor density

It has been shown that Moore's law not only applies to semiconductor density, but it also predicts the increase in (reasonable) simulation sizes, and the reduction in computational simulation run-times.

  Healthcare environment

From the e-Activity, analyze at least two (2) primary economic assumptions and examine their short- and long-term impact on promoting the competitive market model in the healthcare environment. Evaluate the fundamental reasons why price and utiliz..

  What screen enables you to customize files

Which of the following menu commands would you select to make a copy of an open file and rename it. What screen enables you to customize how files will be saved on your computer

  Any rfcs that discuss sip trunking

Write a 500-word paper that explains what a SIP trunk is, why you would use a SIP trunk, the equipment required for its use, and any RFCs that discuss SIP trunking.

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