List Interface Class That Has Operations For Linked List And LList Class
Oct 6, 2014
I have this ListInterface class that has operations for my linked list and a LList class. The Llist and ListInterface classes are perfect. My job is to create a driver, or a demo class that showcases these operations. That being said, heres the driver so far:
import java.util.*;
public abstract class DriverWilson implements ListInterface
{
public static void main(String[] args)
{
So we have an assignment regarding a linked list implementation of a given list interface.
In my list interface, the method contains(T anEntry) is defined.
In the LList implementation, contains is already implemented as part of getting the core methods in.
Now I am being tasked with the following:
Provide a second implementation of the method contains2(T anEntry) that calls a private recursive method
Private boolean contains (T anEntry, Node startNode) that returns whether the list that starts at startNode contains the entry anEntry.
I've written the private recursive method already. That's not an issue (at least not right now).
But what I don't understand is how startNode is supposed to be populated when this private contains method is called from the public contains2 method? contains2 only takes one parameter: anEntry. the private method takes two parameters: anEntry and startNode. How am i supposed to provide startNode when I am calling contains2?
I have to write a test class for a Contacts class called ContactTest and store the instances of Contacts created into a LinkedList.The ContactTest class should implement the addition andremoval of contacts to the Linked List and display its contents.
So far I have this, which stores the information entered into a Linked List, the problem is I don't know how I go about doing the addition and removal part.
Contacts Class
public class Contacts implements InterfaceContacts { String fname; String lname; String phone; String email; //constructors public Contacts( ){ this("****", "****", "****", "****");
I want to create java program in which i want to inherit stack and queue from a linked list class and also make infix to postfix inherit from stack and periority queue from queue class.Ho can i make this program.
I have some class called sorted to sort the linked list through the nodes of the list. and other class to test this ability, i made object of the sort class called "list1" and insert the values to the linked list.
If i make other object called "list2" and want to merge those two lists by using method merge in sort class. And wrote code of
list1.merge(list2);
How can the merge method in sort class know the values of list1 that called it as this object is created in other class.
public void add(int d){ listNode l = new listNode (d, null); l.next = first; first= l; } public list Sum2List (list l1, list l2){ //variables int sum;
[Code] .....
But I have a problem in my first listNode where it ll be pointing to null, thus in the sum2List method the program checks the while condition into false and doesn't go through the loop.
I have a list of uninstanciated class types and I wanted to call a static function from these "Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance but it appears I cant do that in java so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance but this code dont compile:
Java Code:
public PropControl Create(Class<? extends PropControl> cls) { if(cls==HouseControl.class) <---- ERROR { here I create a new instance of HouseControl (that inherits PropControl) } } mh_sh_highlight_all('java');
I get this error :
incomparable types: Class<CAP#1> and Class<HouseControl>
where CAP#1 is a fresh type-variable:
CAP#1 extends PropControl from capture of ? extends PropControl
I'm just putting together a little 'horse racing' program while I'm learning Java, and I have a class called Race that creates an array list of thorougbred horses called field, and asks the user to enter then names of the each horse in the field, with a maximum of 14 horses. The problem occurs with the current code that I have:
import java.util.*; public class Race { RaceHelper helper = new RaceHelper(); ArrayList<thoroughbred> field = new ArrayList<thoroughbred>(); public void setField() { //enter the horses in the race and determine the size of the field
[code]....
the statement of the index position and current size was for me, so I could see what was going on.What I don't understand is the while loop. not that the class doesn't compile and run (you can see that it does), it's the output. Why does the <= sign allow one more entry and increase the size of the field to 15?
Less than or equal to 14 should give a maximum field size of 14, right, With the starting object at index position at zero and going up to 13, for a total size of 14 thoroughbred objects if I just use while (field.size()<14) or a for loop, then the output is fine; it allows a max of 14 entries and prints the results. I thought it had something to do with the size being zero based, but that doesn't seem to matter -- unless it does matter and I'm missing it. why the comparison I'm using produces this output? a field of 14 horses shouldn't matter whether it's zero or 1 based, as long as the size of the field is 14, so why the extra entry with this while condition?
I have a class with static ArrayLists to hold objects such as Members,Players etc.I want to save the class with the arrays so as to reload them again and hold onto the list of objects within those ArrayLists.
The ArrayClass
import java.io.Serializable; import java.util.ArrayList; public class ArrayClass implements Serializable {
[code]....
The arrays within the ArrayClass are empty when i reload the application.I cant tell if the arrays are being properly saved or is it in the reloading from file???
I am trying to create a GUI interface in swing which consists of four classes: a GUI class, which creates a main JPanel, a label, and a JList, which it takes from the second class, a MovesList class that contains a JList and the stuff needed to interface with it. It also has a main class, which basically just creates an object of the GUI class for the main window, and an Other class from which I would like to be able to add an item to the JList. I created methods in the MovesList class to get each component (like getMoveslist, or getMovesListScrollPane), which I then used to create the JList in the GUI class. I also created an addMove method so that I can add an item to the JList from any class through a MovesList object. However, this addMove method only works when called from the GUI or MovesList classes -- it does nothing when I collect from the Other class.
Here is my code:
//Main class public class TestProject { public static void main(String[] args) { GUI mainWindow = new GUI(); mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
[Code] ....
When I run this code, I get a window with a JLabel that says "Moves," and a JList that contains five elements -- test 1-test 5, but not a sixth "test from other class." ( using the add move method ) However, when I click on the window, the addMove method is also called, and successfully adds "test 6" to the list.
I am a beginner here at JAVA and I am trying to program a Gratuity Calculator using both interface class and object class but it keeps on compiling with errors saying "cannot find symbol".I tried everything to fix it but it just keeps on stating symbol.
[CODE] public class GratuityCalculator extends JFrame { /* declarations */
// color objects Color black = new Color(0, 0, 0); Color white = new Color(255, 255, 255); Color light_gray = new Color(192, 192, 192);
What I'm supposed to do is make a method to insert a set of Tiles to the list,i.e.,a detour(make sure that the inserted detouris compatible with thecurrent path so that the resultingpathdoesnot have any gaps). But I'm confused on how to go about doing it. I was thinking of maybe just adding 1 to the current Node.
import java.io.File; import java.io.FileNotFoundException; import java.util.List; import java.util.Scanner; public class Path { static Tile startTile;
I'm trying to implement an Office class that contains an inner class: WorkerNode. The WorkerNode class has a name attribute (String) and WorkerNode attributes for boss, peer and subordinate. The attributes of Office are manager and current which are WorkerNode references. The manager refers to the entry point of the structure and current is the current node in the structure. For simplicity, i'm going to try to limit it to 3 levels and assume that the names are unique. I've put together a Office class that containing main and provided the code I've worked on so far.
public class Office { public static void main(String[] args) { String name=Input.getString("input the manager's name: "); Office office=new Office(name); int option;
I have made a node class and im trying to implement a sorting method. I must use a selection sort but with specific instructions: "Your method should not need to use the new operator since it is just moving nodes from one list to another( not creating new nodes)
this is my current implementation ..but i am instantiating new object..
public class NodeInt { private int data; private NodeInt next = null; public NodeInt(){} //precondition: //postcondition: public NodeInt(int data, NodeInt next) { this.data = data; this.next = next;
[code]....
edit: this is the part that worked but i had it commented out so i have the previous and current declared above but didnt copy.
Ok here I have a code that generates 1 million random values then converts them to a string then hashcode. I then insert into a linked list and then I want to run through each hash and find it in the linked list timing each run then averaging out the time at the end.
It works great for smaller amounts of numbers it is searching for (fine under 50 thousand searches for the for loop starting at line 24 LinkedListTest.java) but when I try to do the full million searches it gives me "a Exception in thread "main" java.lang.StackOverflowError" at line 158 in List.java. Maybe im getting tired but I cannot figure out why.
// class to represent one node in a list class ListNode< T > { // package access members; List can access these directly T data; // data for this node ListNode< T > nextNode; // reference to the next node in the list
if one address point on another address. so set and get methods will be less efficient then an array, but add or remove will be more efficient by a linked list ? a linked list also inherit from queue so if i add an elemnt via "addFirst" function . where its adding the element ? to the right most or left most ? if i have for example :
here [ ] --> [ ] --> [ ] --> [ ] -->[ ] or here
linked list its FIFO so the head will be the right most ?
Edit : its confused me a little bit but i understood now .so it will be at the left most. its actually ordered . not like the stack which is LIFO.
I searched a lot but can't seem to understand the sorting of a SLLNode... I noticed a method called Bubble Sort, I understand how it works, but can't think of a way to implement it to my code..
I'm having some trouble with figuring out how to move along a doubly linked list for an assignment. The program is supposed to be a simple board game simulation. Here is what I have so far:
Space.java:
public class Space { private String name; public Space next; public Space previous; public Space(String name) { this.name = name;
[Code]...
I seem to have been able to get all the other methods working properly, but I am pretty stuck on how to do the movePlayer. Specifically because it is passing an integer, but my objects are of type Space and Boardgame.
i tried everything but its giving me errors. i tried the for loop but its giving me something else.
this is what i have to do Write a recursive method that prints out the data elements of a linked list in reverse order.
Your method should take in as a parameter the head reference to a linked list. Then, write a recursive method that returns a count of the number of elements greater than a given threshold. You may assume that the data elements in the linked lists are ints. The parameters of your method are a reference to the linked list and a int value representing the threshold.
public class recursion3 { public static void main(String [] args) { char a [] = {'A', 'B','C','D','E'}; System.out.println(a); } public static String reverseString(String s) { if (s.length() <= 1) {
I'm trying to print the contents of my linked list. I'm using nodes and within those nodes it hold String data. So i want to print out the data within the nodes. Whenever i do
System.out.println(node1.data),
it prints perfectly. But i'm trying to use a method where it would loop through the list and print out the data for every node in it. when i run my print method i get results such as
Node@15db9742 Node@6d06d69c Node@7852e922.
Here is my print method i created
Java Code:
public void print(){ Node<E> current = head; while (current.next != null){ System.out.println(current.data); current = current.next; } } mh_sh_highlight_all('java');
I am creating a recursive method to reverse a linked list in java. It works the first time when I call it, but I want it to work where I call it a second time and it reverses it to the original state. How can I get that to work with this implementation?
public void reverseList() { System.out.printf("%-16s%-3s%n", "Name", "Score"); System.out.println("--------------- -----"); reverseList(first); } public void reverseList(Node aNode) { if (aNode != null) { reverseList(aNode.next); System.out.printf("%-15s%6s%n" , aNode.name , aNode.score); } }
I am trying to advance to the next node in my linkedList. Below is what i have so far.
/** * Move forward, so that the current element is now the next element in this sequence. * @param - none * @precondition: * isCurrent() returns true. * @postcondition: * If the current element was already the end element of this sequence (with nothing after it), then there is no longer any current element. * Otherwise, the new element is the element immediately after the original current element. * @exception IllegalStateException * Indicates that there is no current element, so advance may not be called. **/
I create and populate someLinkedList with '*' characters as soon as a gameLinkedList object is created, so my class is something like
private int size; public class gameLinkedList{ private CharNode game; public gameLinkedList(String someWord){ size=someWord.length(); for(int i=0;i<size;i++){CharNode aNode = new CharNode('p');
i'm currently going over single linked list, and i'm coming across an error which i do not know how to get by. I'm using single linked list for now just for study purposes, then i would move on to double.
Error: No enclosing instance of type LList is accessible. Must qualify the allocation with an enclosing instance of type LList (e.g. x.new A() where x is an instance of LList).
public class LList { private static class Node<E>{ private E data; private Node<E> next;