QuestionQuestion

Problem 2 – Text file processing
Binary files are convenient to computers because they’re easily machine readable. Text files are human readable, but require parsing and conversion to process in the computer.
The Java String class defines the following method to split a Java String object into multiple fragments of substrings and store them in a returned String array:
String[ ] split( String regularExpression)

The regularExpression argument specifies a delimiter or separator pattern.
The following example uses “-“ as a separator to split a String object:
String initialString = "1:one-2:two-3:three";
String[ ] fragments = initialString.split("-");

The resulting fragments array contains three Strings of “1:one”, “2:two”, and “3:three”. One can further split these fragments if needed. For example,
String[ ] pair1 = fragments[0].split(":");

The pair1 array contains two String objects of “1” and “one”.
Given the following line in a text file:
A=Excellent B=Good C=Adequate D=Marginal E=Unacceptable

Write a method that would read this text file and print out the following:
Grade A is Excellent
Grade B is Good
Grade C is Adequate
Grade D is Marginal
Grade E is Unacceptable

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.io.*;

/**
* An abstraction of an array of integers stored on disk.
*
* @author
* @version 1.0
*/
public class IntDiskArray {

RandomAccessFile file;
int size;
String fileName;
   
    /**
    * Build an abstraction of an array of integers on disk. If the file exists,
    * it should be opened and its length calculated (size parameter is ignored).
    * If the file doesn't exist, it should be created and size zeros should be
    * written to the file.
    *
    * @param fileName the file to open or create
    * @param size the size of the array (in elements)
    * @throws IOException
    */
    public IntDiskArray(String fileName, int size) throws IOException {
    this.fileName = fileName;
       File f = new File(fileName);
       if(f.exists()) {
       file = new RandomAccessFile(fileName, "rw");
       this.size = (int) file.length();
       }
       else {...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$28.00 $14.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats