// for every attribute not mentioned in the rule r
enumAtt = ruleE.enumerateAttributes();
while (enumAtt.hasMoreElements()) {
Attribute attr = (Attribute) enumAtt.nextElement();
if (isMentionedIn(attr, r.m_test)) {continue;}
int M = attr.numValues();
[Code] ....
It repeats only the last rule , why is that !!!!!!
I am working on a assignment that has to do with array lists, it mainly has to do with adding new elements, telling then where it is it located, if the memory block is empty , ect. so far i have been having problems with my indexOf method which should display the array cell number that a input element E is in, and if it is not in there it should display a -1.
public class MyArrayList<E> { private E[] data_store = (E[])new Object[2]; private int sizeofa = 0; private void resize()// makes the array list bigger if need { E[] bigspacemaker = (E[])new Object[data_store.length * 2]; for(int x = 0 ; x< sizeofa ; x++)
[Code] ....
Error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 512 at MyArrayList.indexOf(MyArrayList.java:28) at MyArrayListDemo1.main(MyArrayListDemo1.java:26)
I know there was a change in the later versions of Java where the C++ equivalent of a <template type> was added. Unfortunately the change has 'broken' my older code. If I have a JList and I want to add elements to it then now I should specify the type e.g., the list will store Strings. When I do this and then add data to the list (or actually the list model) the code is ''fixed". However if after adding those new elements to the list I later need to add more elements, which isn't unreasonable for a list...to have elements added dynamically at run time then I again get the same compiler error message that I haven't correctly specified the type:
// Error message during compilation Note: Driver.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
// My code
// Problem here: I try to add new elements to the list. It's the very last line of the method that results in the error. I tried various things such as:
// model.addElement(<String> s); // but so far nothing has worked. How do I add new elements to the list (model)? public static void m2(JList <String> list) { String s; int i; String [] array = new String[10];
[Code] ....
// Code is OK: Create the array of strings to add to constructor of the JList
public static String[] m1(){ String s; int i; String [] array = new String[10]; for (i = 0; i < 5; i++) array[i] = i + "*"; return(array);
[Code] ....
// The change I had to make when compiling under the newer version of Java to indicate that the list would store strings
// Things are okay here now but then when I try to add new elements to the model via method 'm2' that's where I get the compiler error
Lets suppose that I pass to the sort method a list of 2 objects of the same class (which implements Comparable interface). I read (in head first java) that one object is compared relative to another with one object calling the CompareTo() while the other object being passed as a parameter to the same method. Now am I safe in assuming that the first object in the list calls the method with the second object being passed as a parameter.And also how does the CompareTo() work if there are more than 2 elements in the list. Which objcet calls the method and which is passed as a parameter?
In my project I need to create a pizza ordering system. I have created a array list of pizza toppings and each pizza topping must have a cost property associated with it, then the user can pick the toppings they want and the cost of each topping will be added up and the total cost of the whole pizza will be displayed. But I don't know how to associate a cost with each topping. I have been told that I can access the cost through a get/set method and store it in a private member variable. But I don't know how to do this?
I've tried to do it, but it hasn't worked. This is the code
If you see in the code below where I print "Would you like to use previous key" I need to be able to save the previous key answers to be used again.. not sure how to go about doing this..
import java.util.Scanner; public class Main { public static void main(String[] args) { String[] studentName = new String[20]; int[] studentAverage = new int[20]; Scanner input = new Scanner(System.in);
For the program I have to create, I need to be able to work with the elements of a circular doubly linked list to do the following:
Find an element in the list (specified as an argument) Insert an element after a specified element (specified as an argument) Delete an element (specified as an argument) Display the elements in the list
I can insert elements and display the elements, but I can't figure out how to search for an element, insert an element after a specified element, or delete an element.
What I am having trouble with is passing the elements in the list as arguments for searching, deleting, inserting after an element.
public class doublyLinkedList { private Node pointer; private Node dLL; private int count;
I have a project I am currently working on using Primefaces and MySQL. I have a page that will display information queried from the database. I have textfields that will display the data from a given record. But I want to ensure that the displayed data cannot be altered. I decided on disabling the textfields unless the create or edit button were clicked. At which point all textfields will be enabled for editing, and cleared if create button was clicked. I want to push the disabling/enabling of the elements back to a managed bean, but I want to have the bean take in two lists or arrays, one containing all elements by ID and one containing a list of exempt elements. Is there a way I can create a List or Array of the ID's that I can send to the bean? I know little in Javascript and previous attempts to implement it have met with little success.
I want to create a list that would contain all and another that would contain the exemptions such as searchField, searchCriteria, searchButton, projectList and viewButton. The actual exemption list is far smaller than the list of all children. I have found sources that can disable the elements with a java bean, but I have not been able to find one that would allow me to define those that should and should not be disabled, then vice versa for enabling.
Im making a simple code to add an array to a List (the code im referring to is <String> )
import java.util.*; public class L5_ArrayListProgram { public static void main(String[] args){ String[] things = {"lasers","ghouls", "food", "dark"}; List<String>list1 = new ArrayList<String>(); for(String x: things) list1.add(x);
My simple question is - what are the <String> ...<String> for? I understand it makes the list1 variable a string, but why is it made like this? do we usualy use <String> when we need to make a variable a String?
I was supposed to write a PolyNode class for each node in the LinkedList, and a Polynomial class which is pretty much the list itself.Here is what I've coded so far:
PolyNode class:
public class PolyNode { private int coefficient; private int exponent; private PolyNode next;
[code]....
The only trouble I'm having with this problem is finding a way to add these two polynomials together. My first attempt at it was to use nested while loops to traverse through both polynomial lists, like so:
public Polynomial addPolynomials(Polynomial p1, Polynomial p2) { PolyNode current1 = p1.getFirstNode(); PolyNode current2 = p2.getFirstNode(); int coeff; int expo; Polynomial polySum = new Polynomial();
[code]....
Basically what this method does:
-Check to see if the exponents between two terms are the same -If true, add their coefficients together -Create a new node for the polySum with that coefficient sum and the particular exponent value -At the end, return the polySum list which should be the sum of two polynomials
The problem with this method is it doesnt account for the values that are left behind because their exponents aren't equal to the exponents of the other list. So, the only terms that are getting added into the sum list are the ones that have the same exponent in both of the lists that are being added together.
I'm having trouble completing my homework. The problem:
>Suppose that you want an operation for the ADT list that adds an array of items to the end of the list. The header of the method could be as follows: public void addAll(T[] items)
>Write an implementation of this method for the class LinearLinkedList
At first this seemed like an easy problem to me. This is the solution I came up with:
public void addAll(T[] items) { int length = items.length; for(int i = 0 ; i < length; i++){ this.addLast(items[index]); } }
However, one of the requirements for the assignment is that we're not allowed to use the addLast method. how else to insert items to the Linked List without this method. These are the user-defined LinearLinkedList and ListNode classes we made during class:
**LinearLinkedList** // Linear linked list class import java.util.NoSuchElementException; public class LinearLinkedList {
Is this the proper way to add to a generic list? My code works just fine, but I got this feeling that there might be some kind of flaw in it or something. Is this pretty much the basic way to add any type of data to a generic list?
import java.util.LinkedList; public class ListOfGeneric<E> { private LinkedList<E> myList;
This is supposed to be a method that adds stars after each item in the list.
Java Code:
import java.util.ArrayList; public class ClientProgram { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("the");
[Code] ...
I'm guessing it's because list.size() changes, though but it should only find that value in the beginning, so it shouldn't be a problem?
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.
import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class array { public static void main(String[] args)
[Code] ...
Is there a way to write this, where, alpha is one array.
Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.
If I have an array of 50 integers, can I break that to read in lines of 10?
This program contains a superclass and a subclass that will gather the following information from the user:
name, address, phone number, and customer number.
Everything works fine except that I have to create a boolean method in this program that is required to determine based on user input whether they want to be added to a mailing list.
I cannot get this method to work with main, each time it is called it will always return the value but main will constantly read the last statement (else, where it will read "not wanting to be added to the mailing list).
The only way I can get this part of the program to work is by adding an equals method in main that ignores the case, but I am required to write a boolean method so this is not allowed.
Superclass:
public class Person { private String name; private String address; private String phoneNum; public Person(String pName, String add, String number) { name = pName; address = add;
I am trying to make a 2d array that keeps track of comparison counts. what I have so far works ok but writes over the previous elements with 0. can't seem to find where I am re-initializing the previous elements.
//this is one of my fill sort arrays
public void fillSelectionArray(int index, long countSum) { //rand = new Random( ); //for ( int i = 0; i < listsize; i++) { selectionList[ index -1] = countSum; // }
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.
I have a list of 100,000 + names and I need to append to that list another 100,000 names. Each name must be unique. Currently I iterate through the entire list to be sure the name does not exist. As you can imagine this is very slow. I am new to Java and I am maintaining a 15+ year old product. Is there a better way to check for an existing name?
I receive a java.lang.NumberFormatException: For input string: ""DepDelayMinutes"" error when trying to filter a list and then assign the results to a new list.
I have edited the code so it is an int that throws the exception so it isn't the presence of a string that is causing the error - java.lang.NumberFormatException: For input string: ""0914"" .
I believe the issue is because of the two sets of double quotes but I do not understand how they came about. The original dataset does not have any quotes whatsoever.
Suppose i have given a List<Intervals> list; I am iterating over list and inserting each element from list into BST, if time require to insert into BST is logn then what is the total time require to insert all the elements into tree ?
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?