Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91549827
  • Price:- $20

Guranteed 24 Hours Delivery, In Price:- $20

Have any Question?


Related Questions in Computer Engineering

Answer the following question how do you represent a node

Answer the following Question : How do you represent a node in a deployment diagram? What kinds of information can appear on a node? The response must be typed, single spaced, must be in times new roman font (size 12) an ...

The correlation between the height of fathers in the

The correlation between the height of fathers in the heights of their sons is r=0.52. Which kind of the following would not change r? a) measuring their height in centimeters rather than inches. b) removing two outliers ...

Create a menu form you will create a menu form using form

Create a Menu Form You will create a menu form using Form Design view. Add three command buttons for the three forms in the database, and then add three command buttons for the three reports in the database. a. Open the ...

Assignment week 5 user acceptance testinguser acceptance

Assignment: Week 5 User Acceptance Testing User acceptance testing, or UAT, is a round of testing in which the users who are expected to use the system after it goes live exercise the system. UAT differs from quality ass ...

Why are we in the golden age of technology entrepreneurship

Why are we in the 'golden age' of technology entrepreneurship? What factors are helping entrepreneurs more rapidly achieve their vision, and with a lower cost?

Scheduling algorithms are again becoming more important as

Scheduling algorithms are again becoming more important as we look at operating system that run on mobile devices. Are their scheduling algorithms different from those found on traditional interactive system? Compare and ...

Probability of weather- money youll make during it-rain

Probability of weather- Money you'll make during it- Rain= .6 $80 Mist= .3 $120 Normal= .1 $200 A) What is the mean? B) What is the variance? C) What is the square root of the variance? I believe this is called the sigma ...

Suppose that we need to send four packets a b c d from a

Suppose that we need to send four packets (A, B, C, D) from a sender to a receiver. Consider two cases. 1) packet B is lost. 2) acknowledgement for packet B is lost. When there is a packet loss, always assume that only t ...

Recently a government department is involved in the

Recently, a government department is involved in the development of an Online Passport Application Platform. The officers in the department are clear about the requirements of this platform. Besides, the functions of thi ...

On microsoft word what would be the advantage of using the

On Microsoft word, what would be the advantage of using the dialog box over setting various tabs directly on the ruler line? In what types of typing tasks would you find using the ruler line helpful?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As