Question: Help with JAVA please: Look at the code for the two classes given, TabSeparatedFile, and CommaSeparatedFile and refactor the code to try to maximize re-use

Help with JAVA please:

  • Look at the code for the two classes given, TabSeparatedFile, and CommaSeparatedFile and refactor the code to try to maximize re-use of common data elements and methods.
  • Add new unit tests as needed to utilize new function names, etc.
  • Create a new super class and extend that in the existing classes.
  • Try to make the two files that were given as small as possible by forcing everything possible up into the super class

public class CommaSeparatedFile { private String fileName; private String separator; private int fileSize;

public CommaSeparatedFile (String file, int size) { this.separator = ","; this.fileName = file; this.fileSize = size; }

public String getFilename () { return this.fileName; }

public int getFileSize () { return this.fileSize; }

public String printComma () { return this.separator; } }

import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*;

class FileTest { @Test public void Test_CSV () { CommaSeparatedFile csv = new CommaSeparatedFile("foo.txt", 1234); assertEquals("foo.txt", csv.getFilename()); assertEquals(1234, csv.getFileSize()); assertEquals(",", csv.printComma()); }

@Test public void Test_TSV () { TabSeparatedFile tsv = new TabSeparatedFile("bar.baz", 9876543); assertEquals("bar.baz", tsv.getFilename()); assertEquals(9876543, tsv.getFileSize()); assertEquals("\t", tsv.printTab()); } }

public class TabSeparatedFile { private String fileName; private String separator; private int fileSize;

public TabSeparatedFile (String file, int size) { this.separator = "\t"; this.fileName = file; this.fileSize = size; }

public String getFilename () { return this.fileName; }

public int getFileSize () { return this.fileSize; }

public String printTab () { return this.separator; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!