I'm not sure this is right... Is there a way to automate this process? What if we have arrays like int[][][] Terms? This is terrible... Is there a software tool for this?
import java.io.*; import java.util.Scanner; public class asciiFile { int height; int width; Scanner input; char[][] poop; public asciiFile(File f) throws FileNotFoundException{ //constructor
[code]...
The constructor is supposed to take an ASCII file, take the numbers in the file, and populate a 2D array with the numbers in the file.
For some reason, the for loop I use to populate the array works outside of the constructor. When I put it in one of the methods, it runs normally. However, when I keep it in the constructor, I get the following error:
Exception in thread "main" java.lang.NullPointerException
a. Write a code that is written inside a body of a method named average that takes two parameters: N that determines number of terms you should calculate the average of and lowBound that is the beginning term of the geometric sequence. if lowBound is 4 and N is 3, then the average of 4, 8, 16 is calculated and returned.
My code runs fine if I set the test as 16, but I can't figure out what I could do to N to have it determine the number of terms. This is what I have so far...
public class AvgIt { public static void main (String[]args) { double result = average(4, 3); System.out.println("Average is " + result);
I have just started learning Java from a local teacher, this teacher said that the Architecture Neutral refers to Hardware while Platform Independent refers to Operating System, but I found a link to a White Paper by James Gosling. The chapter 4 of this White Paper mentions about both binary code format that is independent of hardware architecture and operating system interfaces, but the main point to be noted is that he has put both under the heading Architecture Neutral. Does it mean that the original buzz word is Architecture Neutral, which includes both hardware and operating system independence?
I have seen many ways of describing what objects are, one being that objects are a user-defined datatype. However, if objects are datatypes, then what does that make classes? To me, it seems as though classes should be the "types" of data defined by the programmer, and objects should be the specific "values" of that user defined data type. As an example, an integer would be a class, while 1 would be a "value" of that class, i.e. an object. From this point of view, I don't see why a specific number would be a data type... Therefore, why do we say that objects are user defined data types rather than classes?
This is the method public void populateMatrices(int [][]mat1, int [][]mat2). I know how to do it for one matrix, but what do we do for the additional matrix? Here is the code I have so far.
for (int row =0; row<mat1.length;row++){ for (int column = 0; column<mat1[row].length;column++){ mat1[row][column]=1 + (int)(Math.random()*5);
I have a method that accepts JSONArray as parameter and returns the values of it as ArrayList Object. My question which of these ways is appropriate in populating the ArrayList object this method populates the arraylist upon creation of object (I don't know what the right term to use, but as netbeans IDE suggest, JSONArray object should be final since it was used in inner class.).
private List<String> getStringList(final JSONArray jsonArr) { return new ArrayList<String>() { { try { for (int i = 0; i < jsonArr.length(); i++) { add(jsonArr.getString(i)); } } catch (JSONException ex) { ex.printStackTrace(); } } }; }
this second method is the usual way of populating collection
private List<String> getStringList(JSONArray jsonArr) { List<String> strList = new ArrayList<String>(); try { for (int i = 0; i < jsonArr.length(); i++) { strList.add(jsonArr.getString(i)); } } catch (JSONException ex) { ex.printStackTrace(); } }
What are the advantages and disadvantages between the two? like which is faster? or which consumed larger memory?
I am trying to populate a Jlist for information stored on a database. The database contains football club names, but instead of being populated with their names it just has a hexadecimal reference ( Club@183357c4 ) for each club object.
I have been given a task to do, which is to create a memberList and populate it with data. The constructor has been created with me, but I am required to add code to display the memberList. I am also required to creates a method to display members.This is the method I created:
/** * Populates the list of members. * Displays the membership numbers and names of library members in ascending membership number order. * The first member is selected by default. */ public void displayMembers() { initComponents(); library = new LibraryCoord(); Collection<Member> Member = library.getMembers(); memberList.setListData(Member); memberList.setSelectedIndex(0);
[code]....
The code below TO DO is mine.What is meant to happen when I run the project is for a GUI form list to show the members of memberList. However, it does not.
I have a swing jFrame set up with a control group which contains 3 radio buttons.
When one is clicked it sends its label to a jtextfield in a different class i have code parsing text by a term
Java Code:
Scanner s = null; try { s = new Scanner(new BufferedReader(new FileReader("/Stage_One.txt"))); s.useDelimiter("*"); String total = (s.next()); Pattern p = Pattern.compile("[]+");
[Code] ....
I just need to know how to access the jframe variables (textfields, panels and such) so i can use their inputs in code to filter a text file.
I'm working on a project where I have to take an input text file with terms and create a glossary with hyperlinks. I've got it working halfway. It outputs the html files for some but not all of the terms and I can't figure out why.
I'm getting these errors:
Please enter the location of the input file: data/terms.txt Please enter the location for the glossary: data/testOutput Exception in thread "main" java.util.ConcurrentModificationException at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:953)
I am having a hard time trying to wrap my head around trying to get a couple of columns in a datatable populated with values from a @OneToMany collection. The concept is simple but my brain refuses to grasp it!! I will try to make this brief...
I have several forms built with primefaces 3.5 using NetBeans 8 IDE on a JBoss EAP 6.21 server, and JPA 2.1 annotations. Data is extracted from an Oracle 11 database, which consists of several lookup tables, as well as a primary table and secondary table. Using the EntityManager createQuery method I query the database, which of course returns a resultset. The query grabs all records from the primary, as well as values from 2 specific columns of the secondary database, based on search criteria entered by the user on a primefaces search form. The returned results are then iterated through, this is where I am trying to get the values from the secondary table to populate specific fields in the datatable.Here is the applicable code from the list.xhtml form containing the datatable:
As odd as the code may look (and I will completely understand anyone cringing as to some of the coding methods I use), specifically with the ui:repeat tags nested inside the datatable tag of the list.xhtml form, I strangely do see the values from the secondary table showing up in the form showing the results in a datatable. However, when the user clicks on a specific record in the returned resultset listed in the datatable, another form is opened and populated with the values from the datatable, but the 2 fields on that form that should be populated with the 2 values I referred to before from the secondary table (i.e. policy1Num and totalPayoutAmt) do not have the values in them.
This is partly because I have those 2 fields in the editable form pointing to the managed bean of the secondary table (code from that bean not shown here), rather than the same "polNum. policy1 Num" and "totPayout.totalPayoutAmt" var I am using in the list.xhtml form. How those values are being successfully returned into the datatable of the list.xhtml form - I happened to "stumble" across the use of the "polNum" and "totPayout" vars with the "policy Payment Collection" list. I do not know how to do the same thing for those 2 fields in the editable form.how a datatable gets populated, specifically with values in a @OneToMany collection,
I have created Person.java with the following attributes:
private String firstName; private String lastName; private int age;
My main method parses the XML, loops through each person, and gets the attributes for each.
I need to create instances of my Person class. I could write something like this:
Person person = new Person(); for (int i = 0; i < attributes.getLength; i++) { if (attribute.getName(i) = "firstname") { person.firstName = attribute.getValue(i);} if (attribute.getName(i) = "lastname") { person.lastName = attribute.getValue(i); } if (attribute.getName(i) = "age") { person.age = attribute.getValue(i); } }
Since my actual XML has quite a few attributes, I would rather do something like this:
Person person = new Person(); for (int i = 0; i < attributes.getLength(); i++) { person[attribute.getName(i)] = attribute.getValue(i); }
My code runs and populates an arraylist. However my break statement, while stopping the loop ends up being added to the arraylist. And I'm not sure how to fix this error.
public static void main(String args[]) throws Exception { // declaring variables String input = ""; // creating array list ArrayList<String> nameList = new ArrayList<String>();
We are getting "Code too large" compilation error for one of our class. This class contains public String fields for label ID and value. We use this class for localization, except for English all other language labels come from .properties files.
The reason we are getting this error is because we have a static block in which using reflection we are populating a HashMap with all public fields and their value. The number of fields have gone up to the extinct where we are crossing the 64K limit for a static method. One of the most feasible solution was to use .properties files for English labels as well.
I will be calling this class MyLabels. We defined a super class for MyLabels called MyLabelsExt. And now we are adding labels into the super class instead of the MyLabels. By running some tests we confirmed that the map that we initialize in MyLables class contains all the fields from both MyLabels and MyLabelsExt class.
How is the 64K limit error not coming if the labels are defined in a super class. Does that mean Java is able to identify that some of the fields are coming from parent class, and that is being treated as separate from the child class. And how is the map that we initialize having all the value.
public class CarV5 { // private instance variables String Model1; int endMiles1, startMiles1; double gallonsUsed1, pricePerGallon1;
[Code] .....
When I try to compile the program, its telling me that it cannot find the Dist variable in the main method for calcMPG and calcGPM. I'm not sure if the methods are right for the calcGPM or calcMPG.
The term "Local variable" is related to scope. That is a local variable is one which is defined in a certain block of code, and its scope is confined inside that block of code.And a "Member variable" is simple an instance variable.
I read in a discussion forum that when local variables are declared (example code below), their name reservation takes place in memory but they are not automatically initialized to anything. On the other hand, when member variables are declared, they are automatically initialized to null by default.
Java Code: public void myFunction () { int [] myInt; // A local, member variable (because "static" keyword is not there) declared } mh_sh_highlight_all('java');
So it seems that they are comparing local variables and member variables. While I think a member variable can also be be local in a block of code, isn't it?
I am working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.
Anyway, i am working on simply making the spiral, which should look like the one below.
n = 3
7 8 9 6 1 2 5 4 3
where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.
import java.io.*; public class Spiral { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the number of elements : "); int n=Integer.parseInt(br.readLine());
I have stumbled onto a problem with ArrayLists (not sure if nested ArrayList objects would be a more accurate description) ....
As simply put as I can describe it, I have an Inventory class which creates an ArrayList of a Product superclass, which has two subclasses, PerishableProduct and ItemisedProduct.
By default, the program is meant to have a starting inventory, which is why I have added them in the constructor
public class Inventory { private List<Product> products; public Inventory() { addProduct(new Product("Frying pan", 15, 20)); addProduct(new PerishableProduct("Apple", 5.8, 30, 7)); addProduct(new ItemisedProduct("Cereal", 5.8, 0)); // this is where I am having problems. Wanting to add // objects to the ItemisedProduct's ArrayList for cereal. }
Within the ItemisedProduct subclass is yet another ArrayList which is meant to hold serial numbers.
public class ItemisedProduct extends Product { private ArrayList<String> serialNumbers = new ArrayList(); public ItemisedProduct(String name, double price, int qty) { super(name, price, qty)
[Code] .....
My problem is that I do not know how to populate the serialNumbers ArrayList from the Inventory class' constructor. Because technically, quantity is defined by how many serial numbers are created.
Starting back at my Computer Science program after a few years off. Having trouble making an algorithm to print all permutations of an Int array. For example, Int[] a = new Int[1,2,3] should print :
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
I've google'd a few different algorithms but cant seem to understand what people are doing as they arnt using many comments on their code.
how can I got about sorting an array that contains more than one value in a single element. Such as my array below has 4 values under one element. I know how to sort elements with single values however, slightly confused on this.
import java.util.Scanner; import java.util.Arrays; class Mobile {