7,116 Posted Topics
I'm looking for an algorithm, pseudocode or any langauge, to generate random numbers with the following characteristics: integer values in the range 0-n lower values much more likely to happen than higher values, eg prob of 0 is n/(n(n-1)), prob of n is 1/(n(n-1)) - linear relationship between value and … | |
Re: It looks like the line causingthe error is line 71 above products=(List<Product>) CollectionFileStorageUtility.load(Product.class); I don't have any info on CollectionFileStorageUtility, but it seems to return a `Collection`. In this particular case the Collection is empty, but that's not a problem. Java is objecting you trying to cast a Collection into … | |
Re: You first need to create an instance of InventoryManager - once you have an actual instance then you can do all the following operations using that instance. eg InventoryManager myManager = new InventoryManager(); ... myManager.addProduct(... myManager.getProduct(... Why does it work this way? - one example would be if you had … | |
Re: OK, so you have copied your teachers complete assignment and posted it on a public web site (did you have the copyright owner's permission?). You didn't even bother to explain what help you need. You didn't show the slightest effort to try to do this yourself. I will delete your … | |
Re: Have a look at Oracle's detailed tutorial on JTables http://docs.oracle.com/javase/tutorial/uiswing/components/table.html in the section on Custom Renderers you will learn how to replace cells in the table with the controls of your choice - in this case you need to check if the cell is in a currently selected row then … | |
Re: As you say, in Java Set is an interface for Collections with no duplicates but no information about ordering, so that's completely different from C++ sets which are weakly ordered. (The Java SortedSet interface is one that has ordered elements.) However, some of the Java concrete classes that implement Set … | |
Re: I'm sorry, but lines 26-32 are complete nonsense. Just delete them and start again by doing the following: 1. Keep a copy of the requirements in front of you at all time - they should detail the calculations to be done. 2. Give your variables descriptive accurate names - eg … | |
Re: You didn't say which of the many JSONConverter implementations you are using, and the line numbers in your posted code don't correspond to the exception message, but at a guess its the enhanced for on line 20 that throws the problem, implying that postList is null. Maybe you could print … | |
Re: 1. Use ProcessBuilder, which is the more recent replacement for Runtime exec 2. Parse the args yourself and pass then separately to ProcessBuilder, because its default parsing of command and parameters is a frequent source of problems. eg try something like new ProcessBuilder("cmd", "/c", "C:\\file1.bat").start(); | |
Re: Short answer: javafx.application.Application contains all the code for initialising a JavaFX app. the normal main method just calls Application's `launch` method to get JavaFX initialised. Once FX is ready it calls your `start` method, where you do whatever you want. You can think of `start` being to JavaFX what `main` … | |
Re: The right time to round is when you are converting the floating point value to String - line 1 in the code you posted.Rather than using concatenation to force a default conversion, use String's `format` method to format `(myDiameter - (myPitch * 0.649519))` to the right number of decimals | |
Re: I don't know android Java, but are you sure isEmpty() will be true if the field contains a blank character as opposed to no character st all? | |
Re: "[Ljava.lang.Object;@64bba873" Is the result of your list view calling `toString() `on your data to convert it to a String for display. That output is the default `toString()` that every class inherits form Object - it just shows its class and hash. You need to make your code more explicit as … | |
Re: You just need to get a pencil and paper and work through the order of execution. Something like... doAnagram(4) calls doAnagram(3) (line 27) before it can call rotate (line 32) doAnagram(3) calls doAnagram(2) (line 27) before it can call rotate (line 32) doAnagram(2) calls doAnagram(1) (line 27) before it can … | |
Re: You need an `InputStreamReader` to read and decode text using UTF-16 encoding. You specify the charset when creating the InputStreamReader, eg `InputStreamReader in = new InputStreamReader(myInputStream, StandardCharsets.UTF_16);` Anything you read from that stream will now be interpreted as UTF-16. Depending on your file's byte ordering you may need to use … | |
Re: It won't work because it's too hard to debug. Nobody is going to debug a loop and nested ifs that stretch over 200 lines - it's just too hard. Refactor your code so the outer loop fits on one or two screenfulls. Your objective is to make each block of … | |
Re: If x is exactly divisible by y then that means x modulo y must be zero (ie the remainder is zero). Java uses the % operator for modulo | |
Re: Around lines 144-146 you seem confused about what variables you are using. | |
Re: That makes no sense. In Java a string is an internal data item that holds a single sequence of chars A table is either a 2 dimensional GUI component or database table They are completely different things. You can't replace one with the other. Maybe it's an English problem? Give … | |
Re: Here is a brilliantly clear explanation of the difference between validate and revalidate: [url]http://www.jguru.com/faq/view.jsp?EID=88716[/url] @Traps: I don't know why you posted that in this thread, but SwingUtilities.invokeLater runs things on the Swing EDT, and is therefore absolutely NOT intended for "working with large collections of data" - that's a complete … | |
Re: How big do you see this file getting? If it will always fit in memory (say just a few hundred meg) then you can do all the appending editing or whatever in memory and re-write the whole thing at shutdown (and at regular intervals). You can get an awful lot … | |
Re: OK, some small errors there but it's on the right tracks. What help do you need? If you are having problems declaring subclasses this tutorial may help: http://docs.oracle.com/javase/tutorial/java/javaOO/classes.html | |
Re: Your FinalProjectQuestions class is written as if it's a first Java project, not a final. For a final project then you are probably expected to define a class that holds all the information for a face. You create a new instance using the input that you get from the user, … | |
Re: No You use names like BookTitle, but you never declare any variables with those names. Everything in Java must be declared. In your constructor you should initialise the variables you declared on lines 2-7 | |
Re: This is al ablout timing - when things happen. JTextField enterdata = new JTextField(10); s1=enterdata.getText(); This creates a text field and immediately queries it for the text it contains. At this time the text is still "", so that's what yu add to the database. You need to create the … | |
Re: If the program uses the value (and if it doesn't then why have it?) then the program must contain some encoded version of the value and some code to decode it for use. In other words there must be enough information in the program to retrieve the value. So a … | |
Re: The string vaue must be in the range for a byte, ie -128 to +127 (ie -80 to 7f hex). Your value of ac is too large for a byte. If I guess your intent properly, then you can get the result you want by parsing the string into an … | |
Re: Looks like javascript, not java. I've added a javascript tag. | |
Re: OK, yes you can iterate through the `entrySet()` (hint!). For each entry you can `getKey()` and `getValue() `and test them to see if either is the one you want | |
Re: To me it looks like that formula is OK if you number the levels starting a 1, not 0 i level max entries 0 1 2^0 = 1 1 2 2^1 = 2 2 3 2^2 = 4 | |
Re: .java is a source code file so you can't execute it. Yo have to compile it first Compiled java programs that can be executed come in .class files or .jar files If you have a .class file, eg myprog.class, then it's executed by ` javaw myprog` If you have a.jar … | |
Re: Please don't be upset by jwenting - he's notoriously grumpy. There are many tutorials on how to parse XML in Java - just Google for them. As always, Oracle's own tutorials are probably the most definitive, although not necessarily the easiest: http://docs.oracle.com/javase/tutorial/jaxp/index.html | |
Re: I tried reading that a few times, but it still makes no sense, and the code you were given (a) also makes no sense and (b) isn't valid code and (c) goes out of its way to break Java naming conventions just to confuse us all. Since both key and … | |
Re: This looks similar to the problem you posted a week ago (column names not recognised). I see that you have not yet marked that one "solved". Maybe you should fix your first column name problem before trying to move on to this one. In any case, posting the wrong code … | |
Re: The message is saying: Your `iprint` and `preprint` methods have been defined to require a parameter of type `Node1`, but when you call those methods you call them with no parameters. It's aboslutely pointless trying to execute a program that has compile errors like that. ps: Oxiegen: Where is the … | |
Re: Yes, definitely. Here's how it works: You start by doing what you can. When you get stuck, or if you want a review of what you have done, we will help. The key point is don't expect anyone to do it for you; the more effort you show, the more … | |
Re: Looks like `marksC` has been declared but not initialised. | |
| |
Re: To get a floating point division you have to have one or both of the operands to be floating point *before* you do the division. You can make one or both operands `double`, or use this little "trick" int a,b; double ans = a/(b*1.0); // forces dividend to double precision … | |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there. | |
Re: Is the capitalisation of the names the same? | |
Re: Thenumbers are normally handled like you are, but when you get an operator you parse and store the previous number then make a note of the operator. Then when the next number is complete (signified by another operator or =) you can parse the seocnd number and do the arithmetic. … | |
Re: 1. Unicode is not a byte code. 2. The web is full of examples of how to read a file 3. That's enough. This is not a free "we do your homework" service. We help people who are making a genuine effort, we don't help people who are too lazy … | |
Re: Excellent. You have demonstrated your ability to copy your assignment (did you get the author's permission?) and paste it here. What do you expect will happen next? DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting … | |
Re: Line 23 You are incrementing the final value `Numyears` when you should be incrementing the loop variable `i` | |
Re: Yes Right click in the editor Insert Code... Constructor... click the fields you want to include as parameters | |
Re: Start with the classes. These come from the problem domain, not from the database or the GUI. Your Use Cases will help. | |
Re: That seems a decent start. Maybe donor and recipient have enough in common to be subclasses of a Person class? The next step is to take the main use cases and walk through them seeing how easily your classes and methods support the use cases. You may well find that … | |
Re: Is there a pre-defined set of inputs and corresponding outputs? If so a `Map` would be the obvious choice. | |
Re: "didn't work"? Means whay exactly? Error message? Listener not called? Listener called but no panel visible? Panel visible but looks wrong? Come on now, give us some info to work with. |
The End.