Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class that acts as a doubly linked list node. It should contain all the

ID: 3685255 • Letter: C

Question

Create a class that acts as a doubly linked list node. It should contain all the required data fields, at least 1 constructor, and a method that prints the hero’s information. • Create a data file with hero information. Each line should be of the following format: heroName Nemesis Time where Nemesis is 1 for the nemesis and 0 for everyone else and Time is in hours. • Modify your list class to include the following stack methods: push, pop, popAll, printList. • Create a class that contains a main method for testing/demonstrating. • In your main method, thoroughly test/demonstrate the methods from your list that you’ve implemented. You should be able to read your data file and use it to push heroes. hint: I find it helpful to use the scanner class for this but you can use something else if you prefer. You can find the scanner class documentation here: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html. (IN JAVA)

Explanation / Answer

class Node

{

    Data data;

    Node previous;

    Node next;

}

class info

{

    String   hName;

boolean isOnnemesis;

   String date;

}

info(String hName,boolean isOnNemesis,String date){

        this.hName       = hName;

        this.isOnNemesis      =isOnNemesis ;

        this.date = date;

    }

}

class Stack

{

    private static int sizeOfStack;

    private static Node topElement;

public static boolean isEmpty() { return topElement == null; }

public static void Initialize() {

        sizeOfStack = 0;

        topElement = null;

    }

    public static void Push(Data x) {

        Node oldElement = topElement;

        topElement = new Node();

        topElement.data = x;

        topElement.next = oldElement;

        topElement.previous = null;

if(oldElement != null)

{

      oldElement.previous = topElement;

}

sizeOfStack++;

    }

public static void Pop() {

        if (!isEmpty()){

            topElement = topElement.next;   // delete first node

            sizeOfStack--;

        }

    }

public static void Top() {

   String hName=           topElement.info.hName;

       boolean isOnNemesis = topElement.info.isOnNemesis;

        String date =       topElement.info.date;

System.out.println(hName + " " + isOnNemesis + " " + date);

    }

public static void Kill() { }

    public static void Print() { }

public static void main(String[] args){

Push(new info(“Maheshbabu”, true, "01-10-2009"));

        Push(new info(“Sharukh”, false, "05-04-1995"));

        Push(new info(“Rajinikanth”, false, "07-05-1976"));

        Push(new info(“Mohanlal”, true,"04-09-1987"));

        Pop();

        Pop();

Top();

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote