713 Posted Topics
Re: Well, look at tuition. Apparently it's 0.0 when you print it. What happens to it before you print it? How does it get that value? And what happens before that? How does it get the preceding value? Work back through the code this way and you should be able to … | |
Re: You can simplify Taywin's method by starting your flag at 1, and multiplying by -1 at each boundary. Then just add the flag to the current total, and you've eliminated the middle if. You can do simplify further by just counting and then flipping. [CODE]public static void main(String[] args) { … | |
Re: Okay, let's look at the logic of the thing. As you have it now, your calculate method has one serious flaw in it. Walk through the logic manually - what happens if I want to buy 15 slices? If you correct that error (it's a simple fix) then you have … | |
Re: When you pass an object o to println() as its parameter, it typically tries to print it by calling String.valueOf(o) to get a String value. That value is going to be the value returned from calling o.toString(). If that object overrides Object.toString(), then that return value will be whatever the … | |
Re: setHoursWorked is a void return - it doesn't return a value. You can't assign anything to setHoursWorked(), because there's nothing to assign. The best thing to do would be to return the calculated value and leave the assignment, not set "hoursWorked" from within the method. Same problem for setPayRate. | |
Re: That didn't seem right to me, so I tried it. Here's the code: [CODE] public static void main(String[] args) { System.out.println(true?ifTrue():ifFalse()); } public static String ifTrue() { return "It's twue, it's twue"; } public static String ifFalse() { return "You liar!"; }[/CODE] And the output: It's twue, it's twue I … | |
Re: First thing in debugging is to identify the actual problem. In this case, it's one that every programmer in a C-type language commits early on, and I'm going to let you find it yourself, because the facepalm you will undergo will mean you never make this mistake again. The most … | |
Re: Sorry, but nobody here is likely to do your homework for you. If you're having trouble with code you've written, post the code and I'm sure you'll find some assistance. To get started on a project like this, identify the entities involved - who does what and with which and … | |
Re: There are a few underlying things you need to understand. One is that an array is a collection of items, and each element of the array is a single item. Another thing is that you'll have an easier time of it if you handle your data, logic, and presentation separately. … | |
Re: [QUOTE=ajst;1407385]what you can do is rather then running the inner loop to the same number as the outer loop get it to stop at half of the outer loop. that way it will not create duplicates or have to waste time comparing if its in list allready [/QUOTE] Doesn't help … | |
Re: [QUOTE]prolly just a memory address[/QUOTE] That'll be right. An array is an object. If you feed an object as the argument to a print or println, it'll generally try to print it by calling String.valueOf(the object). That behavior is defined in the API, under String: [QUOTE] valueOf public static String … | |
Re: Start by charging $250. For each visit over 5, charge $55. That is, if visit > 5, add (visit-5)*$55 to the $250 initial fee. Here's one of the things you might want to iron out: [CODE] while ((visit >= 0) && (visit <= 5) { total = flatRate; } [/CODE] … | |
Re: To read this stack trace, look at the first line you see. That'll tell you what exception is being thrown, in this case an InputMismatchException. Since this is a Java object produced by Sun, it's [URL="http://download.oracle.com/javase/1.5.0/docs/api/java/util/InputMismatchException.html"]documented[/URL] and you can read up on what Sun has to say about it. The … | |
Re: Translation is actually quite a hard problem. I don't think you're going to solve it with simple search/replace. I heard an interesting talk last year by someone working in this area, and it sounds to me like most of the serious machine translation out there relies more on statistical matching … | |
Re: This code here doesn't actually open or write to a file, so it's hard to say what your error might be. It's very possible that it's something to do with the file mode, as Taywin suggests, or some other error, but here all you do is identify a file and … | |
Re: Start by figuring out what the steps are at a high level, then figure out how to execute them. Executing them may, and probably will, involve decomposing them into steps which you'll then re-examine in the same way until you have methods which are trivial to execute. Write the trivial … | |
Re: I'm sure there are practical uses that others will be happy to detail. The pedagogical use, though is worth mentioning: I'm learning assembly to understand the machine better, and to get a better handle on what I'm doing in C. I don't think I'm going to generate any non-trivial code … | |
Re: [CODE]Homework3.compareTo(al.get(i));[/CODE] Homework3 is a class. It can't be compared to a Homework3 object, any more than you can compare the Integer class to the Integer 3. Calling a method in the form ClassName.method() is calling it as a static method - it's calling it without reference to any particular object … | |
Re: [QUOTE=Momerath;1493627]How can you own them and not be responsible for them? [/QUOTE] Nothing very odd about this. When I look at, say, my old DAW science fiction anthologies, I see that the copyright page lists the magazine of first publication as the copyright holder, but nobody would ever suggest that … | |
Re: 1) Yes, it's possible. What'll happen is the first value will be overwritten, though, which isn't what you want. I'd look again at your structure. If person to phone number is a one to many relationship, perhaps you want to map names to arraylists of phone numbers. If there are … | |
Re: That's correct. Notice, however, that you're going to have to commit an act of minor barbarism, using a try/catch as a conditional. That is, you're going to put the parseInt in a try block, and if it returns an exception, you're going to take that as a "false". Since there … | |
Re: You'd need something like cbreak mode, which I think you can't get in the console under java. Same reason you can't clear the screen, except by sending a large number of carriage returns. | |
Re: You want the first iteration of the loop to be different from the rest of the iterations? James' boolean flag is one acceptable way to do that. The execution cost of checking that value and then setting firstPass to false at the end of each loop is negligible. However, stylistically, … | |
Re: Popular discussion lately. There are IDEs available for Java. Eclipse is probably the most popular, and it's pretty usable. NetBeans is popular as well, I haven't used it. Both are free. There are others as well. However, I'd suggest that you use an editor and compile direct from the command … | |
Re: When in doubt, try doing it by hand and see what steps you need to take. Here's a random collection of coins: 3 quarters, two dimes, three nickels, and two pennies. Here's another random collection: 4 quarters, 4 dimes, 1 nickel, and 1 penny. Here's another random collection: 1 quarter, … | |
Re: [URL="http://www.daniweb.com/forums/thread99132.html"]Click here[/URL] | |
Re: [QUOTE=frogboy77;1451378]It appears to be the case of those who can, do, those who can't, teach.[/QUOTE] It appears to be the case that there's a lousy teacher in the world. Are you surprised? In my time, I've seen a lot more lousy students than lousy teachers... and usually the lousy students … | |
Re: Look at your while clause: [CODE]while (userNumber >= 0)[/CODE] Under what conditions will that continue to loop? So why doesn't it loop when you want it to? Look at the break at line 22 - what does that mean? There are two idiomatic ways to do a while loop. One … | |
Re: I'm hesitant to leap in here, but there's a bit of confusion that should be cleared up. In ztini's post, he says that "invoking .equals checks whether or not the memory locations are equas". This is true, [b]if[/b] you have not written a .equals() method for your class, and assuming … | |
Re: [url]http://en.wikipedia.org/wiki/Standard_score[/url] Don't thank me. Thank google. First entry under "z-score". Try it some time, it's pretty cool. ![]() | |
Re: 1D is a line. 0D is a Point. If you want to do this OO style, you could make a case for starting for 0D Tic Tac Toe - "Tic" you'd call it, I guess - and working out from there. I bet you he won't do it that way, … ![]() | |
Re: The out of bounds is simple enough. You're going to i<args.length, which is correct. But then in the loop, you're addressing args[i++] - this means you're addressing args[length] in the last time through. That address doesn't exist, so there's your outofboundsexception. The sort you're describing is more or less a … | |
Re: Simpler explanation: [url]http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[/url] Simpler explanation than that: float is 32-bit, double is 64-bit. Simplest explanation: just use double and ignore float. | |
Re: A tokenizer turns a raw input sequence into a sequence of "tokens", which your parser can then accept for further processing. It will often attempt to recognize keywords and return "tokens" of that type, and return unrecognized items as literals - so [CODE]if (a == b) { c = d; … | |
Re: If you want to understand java, skip the IDE, get a proper text editor, and compile from the command line. Once you're developing larger applications, it might make sense to start using an IDE, but for now features like auto-completion, syntax highlighting, and the like will only insulate you from … | |
Re: [QUOTE=wonder_laptop;1486498]i dont see where i can integrate this in my code..[/QUOTE] If I understand priteas, he's suggesting you make an arraylist of Integer, populate it with integers in the range you want, and remove(randomIndex) for your random numbers, randomIndex being a random int in the range (0..arraylist.size()) Instead of [ICODE]idx … | |
Re: Am I correct in thinking the whole thing is an array of Strings, each row is a String? If so, you can use Java's regex which is not too far from perl's. The major difference is that regexen are created as Strings, which means you have to worry about escaping … | |
Re: [QUOTE]The simplest solution would be to write out a new file with the updated data and delete the original one[/QUOTE] Seconded. Read in the file, modify it in memory, write it out when you're done, overwriting the original. Write out a backup of the original first if you're concerned about … | |
Re: The return statement error is not hard to spot, although it would be easier if you tried to simplify your code a little. One way to find this is to trace the logic of that method - make sure that every branch leads to a return statement. You should find … | |
Re: I will be happy to explain the answer - your confusion here is actually reasonable - if you'll be kind enough to a)start a new thread for this question, since we don't like new questions in old threads, it's contrary to the house style and b) put code tags around … | |
Re: Previous poster is absolutely correct. Absolute index of an array arr[] must be in the range [0..arr.length-1] - can't be negative, can't be equal to or greater than the length. Notice I say "absolute index" - that's the index that the compiler sees as the value. Now, suppose you want … | |
Re: Java will not accept a method that is not part of a class. The only things that have methods are classes and objects (classes have static methods, like [CODE]public static void main (String args[])[/CODE] and objects have instance methods like [CODE]public String toString()[/CODE] That's the way it is. Why not … | |
Re: localArrayList.add(arrayOfgz[j] = = paramArrayOfgz[j]); Can you explain what you mean for this line to do? localArrayList is a raw ArrayList, so I've go no clues from the declaration what it is you mean to add here. Are you trying to assign from the paramArray to the array and then add … | |
Re: [CODE] } // end method sphereVolume } // end constructor [/CODE] There's no method "sphereVolume", so one of these ends the constructor and the other ends the class. | |
Re: Speaking of "humor doesn't always come across well" - there are mature and experienced php developers? Who knew? :) | |
Re: manish- read [URL="http://www.catb.org/~esr/faqs/smart-questions.html"]this [/URL] Remember, make it easy for people to help you out. Style matters! | |
Re: Someone who promises to cover all of that in one day might be promising too much. I could tell you how each of those things work over the course of six or eight hours, but most of it requires a certain amount of time at the machine to make sense. … | |
Re: Do you mean something like the fireActionPerformed() method found in AbstractButton? | |
Re: Are you sure the array has non-zero values before the sort? | |
Re: When you create a Vector without a type, it's automatically a Vector<Object> - that is, when you get() something from the vector, all the compiler knows is that it's an Object. When you add() your ints, they're auto-boxed into Integers, which are of course Objects. Fine so far. When you … |
The End.