Answer to Question #250536 in Java | JSP | JSF for Gracey

Question #250536
It is time for you to demonstrate your skills in a project of your own choice. You must DESIGN,
ANALYSE AND CODE any method for the GENERIC MyLinkedList class that will manipulate the linked
list. You can decide yourself what it should be following the specification below:
1. Purpose: The method must make logical sense à ƒ ¢ € “ it should be of some purpose to somebody.
You should describe in the text who will use the method for which purpose.
2. Clearly explain the problem. Then clearly explain how your method will solve it.
3. Test program: Test the method using a wrapped class like Integer however.
1
Expert's answer
2021-10-13T00:29:07-0400

1. A programmer friend of mine will use this method to save information before exiting the program.

2. The data from the list is not saved when the user closes his application. My method will save the data from the list to the selected file.


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public void saveData(String path) {
        try {
            FileWriter fileWriter = new FileWriter(new File(path));
            Node cur = head;
            while (cur != null) {
                fileWriter.write(cur.data + "\n");
                fileWriter.flush();
                cur = cur.next;
            }
            fileWriter.close();
        } catch (IOException e) {
        }
    }

    public static void main(String[] args) {
        MyLinkedList<Integer> list = new MyLinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.saveData("test.txt");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Gracey
14.10.21, 00:34

So much helpful thanks a lot

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS