Question: package prog2; import java.util.LinkedList; import java.util.ListIterator; /** * @author * */ public class FileDict { LinkedList filelst = new LinkedList (); /** * Add the

package prog2; import java.util.LinkedList; import java.util.ListIterator; /** * @author * */ public class FileDict { LinkedList filelst = new LinkedList(); /** * Add the file * @param file - the file to be added * @return false - if the file with the same name is already existed; true - the file added successfully * */ public boolean add(MyFile file) { // TO-DO return true; // remove this line after your implementation } /** * Remove the least recently added or accessed file * @param - the given file name * */ public MyFile remove() { // TO DO return null; // remove this line after your implementation } /** * Access a file with given filename, * @param filename - the name of the file to access * @return the file accessed, or null if no such file exists */ public MyFile access(String filename) { // TO DO return null; // remove this line after your implementation } /** * This method return the least recently used file, i.e. most recently accessed or added * Should be done O(1) time cost * * @return the least recently used file; or null if empty list */ public MyFile lruFile() { // TO DO return null; // remove this line after your implementation } /** * This method return the most recently used file, i.e. most recently accessed or added * Should be done O(1) time cost * @param filename * @return the most recently used file; or null if empty list */ public MyFile mruFile() { // TO DO return null; // remove this line after your implementation } /** * Re-oder the files based on priorities, higher priority file placed first; ties are broken by * filename in reverse alphabetical order * Hint: You may need to add CompareTo function in MyFile Class */ public void reoderFiles() { // TO-DO } public String display() { return filelst.toString(); } }

/** * */ package prog2; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; /** * @author * */ public class TestFileDict { FileDict dt; @Before public void setUp() { dt = new FileDict(); dt.add(new MyFile("Abe", 5)); dt.add(new MyFile("Sample", 1)); dt.add(new MyFile("Dock", 3)); dt.add(new MyFile("Book", 5)); dt.add(new MyFile("Note", 3)); } @Test(timeout = 100) public void testdisplay() { String ret = "[Note|3, Book|5, Dock|3, Sample|1, Abe|5]"; assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testlruFile1() { assertEquals("Abe", dt.lruFile().getFileName()); } @Test(timeout = 100) public void testmruFile1() { assertEquals("Note", dt.mruFile().getFileName()); } @Test(timeout = 100) public void testmruFile2() { dt.access("Book"); assertEquals("Book", dt.mruFile().getFileName()); } @Test(timeout = 100) public void testremove() { String ret = "[Note|3, Book|5, Dock|3, Sample|1]"; dt.remove(); dt.display(); assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testaccess1() { String ret = "[Abe|5, Note|3, Book|5, Dock|3, Sample|1]"; dt.access("Abe"); dt.display(); assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testaccess2() { String ret = "[Book|5, Note|3, Dock|3, Sample|1, Abe|5]"; dt.access("Book"); dt.display(); assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testaccess3() { String ret = "[Sample|1, Note|3, Book|5, Dock|3, Abe|5]"; dt.access("Sample"); dt.display(); assertEquals(ret, dt.display()); ret = "[Dock|3, Sample|1, Note|3, Book|5, Abe|5]"; dt.access("Dock"); dt.display(); assertEquals(ret, dt.display()); } @Test(timeout = 100) public void testreorder() { String ret = "[Book|5, Abe|5, Note|3, Dock|3, Sample|1]"; dt.reoderFiles(); dt.display(); assertEquals(ret, dt.display()); } }

/** * */ package prog2; /** * You are free to add more methods, implements an interface or extends a class * @author */ public class MyFile{ private String fileName; private int priority; // higher value means higher priority /** * @return the fileName */ public String getFileName() { return fileName; } /** * @param fileName the fileName to set */ public void setFileName(String fileName) { this.fileName = fileName; } /** * @return the priority */ public int getPriority() { return priority; } /** * @param priority the priority to set */ public void setPriority(int priority) { this.priority = priority; } /** * @param fileName * @param priority */ /* * Please don't change this implementation */ public MyFile(String fileName, int priority) { this.fileName = fileName; this.priority = priority; } /* (non-Javadoc) * @see java.lang.Object#toString() * Please don't change this implementation */ @Override public String toString() { return fileName + "|" + priority; } }

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!