Question

Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static i...

Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example:

public class Test{
public static int timesTwo(int value){
return value * value;
}

}

public class TestDriver{
public static void main(String[] args){
int var = Test.timesTwo(5);
  System.out.println(var);
}
}

For your final exercise, create a class called ManyLinkedLists. It will contain a static method called createLinkedList(). That method takes an argument that is a constant defined in the ManyLinkedLists class. The identifier of the constants should describe a type of linked list. When the createLinkedList method is called, it should return a linked list object of the type identified by the constant.

For example:

DoubleEndedList del = ManyLinkedLists.createLinkedList(ManyLinkedLists.DOUBLEENDEDLIST);

Give the createLinkedList method the ability to return the linked lists described below:

  • A double-ended linked list. That kind of linked list is described in chapter 5 of your text (starts on page 198).
  • A doubly linked list. That kind of linked list is described in chapter 5 of your text (starts on page 221).


Note that in order to create the above linked lists you will have to create something equivalent to the Link class from exercise 5A. Use a long instance variable as the data within your link class or classes.
Your project should contain any other classes you need. Include a ManyLinkedListsDriver class that tests the ManyLinkedLists class, its method, and the data structures that the method can return. The peculiar features of the two forms of linked list should be clearly demonstrated.

Include a document in your submitted project that clearly explains the difference between a double-ended linked list and a doubly linked list.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class ManyLinkedLists {
   static int DOUBLEENDEDLIST = 1;
   static int DOUBLELIST = 2;
  
   public static LinkedList<String> createLinkedList(int typeof_Linked_List) {
       if(typeof_Linked_List == ManyLinkedLists.DOUBLEENDEDLIST) {
           //return doubleendedlist
       }if(typeof_Linked_List == ManyLinkedLists.DOUBLELIST) {
           //return doublelist
       }
       return null;
   }
   public static void main(String[] args) {
       LinkedList<String> output = ManyLinkedLists.createLinkedList(ManyLinkedLists.DOUBLEENDEDLIST);
   }
}

Add a comment
Know the answer?
Add Answer to:
Static methods can be called directly from the name of the class that contains the method. Static methods are usually created to do utility operations. For example: public class Test{ public static i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the following method as a new static method for the IntNode class. (Use the usual...

    Implement the following method as a new static method for the IntNode class. (Use the usual IntNode class with instance variables called data and link.) public static int count42s(IntNode head) // Precondition: head is the head reference of a linked list. // The list might be empty or it might be non-empty. // Postcondition: The return value is the number of occurrences // of 42 in the data field of a node on the linked list. // The list itself...

  • 9) Write out the following method as a static method for the IntNode class (similar to...

    9) Write out the following method as a static method for the IntNode class (similar to the book: use data & link) public static int count10s (IntNode head) I Precondition: Head is a reference to a linked list of integers, Il condition of the list is unknown (empty or not) // Postcondition: Method returns number of 10s found in the linked list. / list is unchanged. 10) Write out the following method as a static method for the IntNode class...

  • List of Candles Create a class called CandleNode which has fields for the data (a Candle)...

    List of Candles Create a class called CandleNode which has fields for the data (a Candle) and next (CandleNode) instance variables. Include a one-argument constructor which takes a Candle as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CandleNode (Candle c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CandleList. This...

  • Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element...

    Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element stored at this node */ private int element; // reference to the element stored at this node /** A reference to the subsequent node in the list */ private Node next; // reference to the subsequent node in the list /** * Creates a node with the given element and next node. * * @param e the element to be stored * @param n...

  • if we have following List classes: public class LinkedList<T> { class ListNode { protected T value;...

    if we have following List classes: public class LinkedList<T> { class ListNode { protected T value; protected ListNode next; public ListNode(T val, ListNode nxt) { value = val; next = nxt; } public ListNode(T val) { this(val, null); } public ListNode() { this(null, null); } } can you write the folowing methods in java: 1.Write a method for the LinkedList class called int indexOf(T val) which returns the integer index indicating the location of val in the list, or -1...

  • Create a class called CompareArrays that determines if two specified integer arrays are equal. The class...

    Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. Create a second class called CompareArraysTest that contains...

  • C++ This exercise will introduce static member variables and static methods in class to you. Class...

    C++ This exercise will introduce static member variables and static methods in class to you. Class Department contain information about universities departments: name students amount in addition it also stores information about overall amount of departments at the university: departments amount class Department { public: Department(string i_name, int i_num_students); ~Department(); int get_students(); string get_name(); static int get_total(); private: string name; int num_students; static int total_departments; }; Carefully read and modify the template. You have to implement private static variable "total...

  • I need help with the Implementation of an Ordered List (Template Files) public interface Ordered...

    I need help with the Implementation of an Ordered List (Template Files) public interface OrderedStructure { public abstract int size(); public abstract boolean add( Comparable obj ) throws IllegalArgumentException; public abstract Object get( int pos ) throws IndexOutOfBoundsException; public abstract void remove( int pos ) throws IndexOutOfBoundsException; public abstract void merge( OrderedList other ); } import java.util.NoSuchElementException; public class OrderedList implements OrderedStructure { // Implementation of the doubly linked nodes (nested-class) private static class Node { private Comparable value; private...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • PrintArray vi Create a class called PrintArray. This is the class that contains the main method....

    PrintArray vi Create a class called PrintArray. This is the class that contains the main method. Your program must print each of the elements of the array of ints called aa on a separate line (see examples). The method getArray (included in the starter code) reads integers from input and returns them in an array of ints. Use the following starter code: //for this program Arrays.toString(array) is forbidden import java.util.Scanner; public class PrintArray { static Scanner in = new Scanner(System.in);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT