226 Posted Topics
Re: That sort of problem has nothing to do with your Java source code. The problem must be in your Ant buildfile. You should look to the XML to find whatever is causing your trouble. | |
*Code Complete* is a programming book by Steve McConnell which includes a second about how to choose a language for your project. It very briefly examines a wide variety of languages: Ada, Assembly, C, C++, C#, Cobol, Fortran, Java, JavaScript, PHP, Perl, Python, Smalltalk, SQL, and Visual Basic. It also … | |
Re: Those repeated lines are produced by this loop: for (int total=firstNum;total <= secondNum; total++) { int sumMinusFirstNum=sum-firstNum; finalSum=sumMinusFirstNum-secondNum; bw.write("Sum of all numbers in between "+Integer.toString(firstNum)+ " and " +Integer.toString(secondNum)+": "+finalSum); bw.newLine(); } I am curious to know why you have a loop if you want to write the line just … | |
Re: It's strange, but from the requirements of `WalletTest` it seems that you will need to keep track of possible 2-cent pennies and 7-cent dimes. But at least there's no reason to change the name or value of a coin, so you shouldn't have those setters in `Coin`. Instead you should … | |
Re: You want to include color information in an OutputStream, but OutputStreams don't naturally contain color information. You need to depend upon wherever your stream is going to make the color happen. Some places that read the content of an OutputStream may be able to recognize certain codes and display colors … | |
Re: As an experiment, try this: double value = 0; for(int i = 0; i <= 500; i++) { value++; value = Math.pow(value,2); System.out.printf("%d: %f%n", i, value); if(value == Double.POSITIVE_INFINITY) break; } Notice that it only takes 11 times through the loop before it gets to infinity and stops. That's what … | |
Re: The method `getScaledInstance` is much like almost all methods that start with `get` because the important part of calling it is the object that it returns. If you ignore the return value, the point of calling it is lost. The image you want isn't `MyImage`, it is the image returned … | |
Re: I'm impressed by how gentle BlueJ is with its error messages. It tells you the problem twice in two distinct ways. I'm not sure I can add much to that, but you should probably look at lines 6, 79, and 84. Look at them carefully and think about the error … | |
Re: As far as I can see, there is no reason your `printdata` function couldn't take an `ostream` instead of an `ofstream`. Then you could just call `printdata` twice, once with `outputfile` and once with `cout`. | |
Re: Your compiler will catch most of the problems that I see. Your compiler should be the first place you go for checking for problems because it is more reliable than human eyes at finding problems, and usually produces helpful and accurate explanations of the problems. I admit that sometimes it … | |
Re: The documentation for `transferFrom` doesn't seem to promise that it will get your entire file. It says that there are situations where it will only read some of the requested bytes and you are clearly depending on that since I doubt you really want `1 << 24` bytes. You must … | |
Re: I don't see any object being used after it is deleted. There are only two deletions. After the first one the pointer is immediately overwritten, and the second one is practically at the end of the program. Could you provide the line number where a deleted object may be used? | |
Re: I would sort the events by date and then iterate through the list adding one to the population for each birth and subtracting one for each death. | |
Re: The right way to convert an `int` to a `char` is using the `Character.forDigit` method. char b = Character.forDigit(a,10); | |
Re: SortableArrayList nameList = new SortableArrayListWithSelectionSortII(capacity); //output array before sort System.out.println("List of numbers before sort:\n"); System.out.println(Arrays.toString(listItem)); //sort array and display nameList.sort(); //sort list System.out.println("\nList of numbers after sort:\n"); System.out.println(Arrays.toString(listItem)); You create an empty `SortableArrayList` called `nameList`, then you print some stuff that's not connected to `nameList`, then you sort `nameList` even … | |
Re: It is an applet. It needs to be run as part of a webpage, and it works just fine when you use it like that. It draws a car, a house, and a tree with some hills in the background. | |
Re: You can draw images with `java.awt.Graphics.drawImage`. You can draw text several different ways, such as: `java.awt.Graphics.drawString`, `java.awt.font.TextLayout`, `javax.swing.JLabel`, `javax.swing.JTextArea`, and `javax.swing.JTextPane`. Each one works differently so you should investigate them all to find the one you prefer. You can use a `java.awt.event.MouseListener` or `java.awt.event.MouseAdapter` to react to rollovers. That seems … | |
Re: Replace `fc.showOpenDialog` with `fc.showSaveDialog`. | |
Re: You can convert a `char` to a number using `Character.digit(char ch, int radix)`. Considering the restrictions you are given, that seems to be what they want you to do, but don't use `toString`. It would be awkward to read the int in as a String, convert it to an int, … | |
Re: The message `java.util.UnknownFormatConversionException: Conversion = 'r'` means that `%r` is being used in a format string somewhere, and that's not allowed. It must be talking about "10% rise". Turn that into "10%% rise" and the problem will be solved. You must be careful about % in format strings. | |
Re: Applets run in a web browser and can be a part of a website. Aside from some security scares, applets are a fine way to add dynamic content to a web page. A stand alone application cannot be part of a website in the same way. It would at least … | |
Re: It seems clear that yup790 has the mistaken impression that `java.io.LineNumberReader.setLineNumber` should make it possible to move the reader to the start of any given line. When yup790 says > I tried looping through first and that doesn't work. It means reading the entire file and then calling `setLineNumber` in … | |
Re: Launch configurations are also known as Run configurations. If you don't have the configuration that you want in the list you can edit your list of configurations in the *Run Configurations* dialog box which you can get to from the *Run* menu. | |
Re: Actually, `[^BitTorrent]` means any letter that is none of B, i, t, T, o, r, e, or n. It's surprising that deadsolo somehow stumbled onto something so contrary to the solution to the problem even though deadsolo must know how `[]` works. It seems to me that the best solution … | |
Re: Since they are unique numbers I'll suppose you have your numbers in a `Set<Number>`. I'll call it `numbers`. Then I would solve the problem recursively. Write a method something like `Collection<List<Number>> allPossibleOrders(Set<Number> numbers)` and in that method have an accumulator `ArrayList<List<Number>>` and a loop like `for(Number n: numbers)`. For each … | |
Re: I haven't used it, but this looks promising. https://code.google.com/p/google-http-java-client/ Perhaps you could use that or something similar. | |
Re: That may be because a game inventory system seems both too simple and too game-specific for a general purpose tutorial to be valuable. I imagine it might either be an `std::vector` of items or an `std::map` with items as keys and the amount of each item as values. It doesn't … | |
Re: Be aware that if you plan to modify `loop_status` in one thread and read it in another thread without synchronization then it should be declared `volatile` to ensure that both threads have the same value. For example: `public static volatile boolean loop_status = true;` Otherwise it is possible that `loop_status` … | |
Re: It is impossible to literally write a variable to a file because files can only contain values, not variables. Normally when someone says "write a variable to a file" that person would mean to write the value of the variable to a file, but in that case the person wouldn't … | |
Re: In a queue you can cycle it around by taking the element at the head of the queue and moving it to the end. Doing this repeatedly will give you access to each element of the queue in turn without requiring any additional storage. In a stack you need to … | |
Re: printf(" "); //output a blank space when if not true You say "if not true" in the comment but you don't actually do any test to make it happen that way. That `printf` will be happening every time through the loop. It is making the top and bottom of your … | |
Re: Instead of calculating the present value of a million dollars twenty years in the future, you are calculating the present value of a million dollars a million years in the future, and that is much less than one cent. The result of `Math.pow(1+(annualIntrestRate), futureValue)` is `Double.POSITIVE_INFINITY` so it's mostly by … | |
Re: I haven't been able to find any clear documentation on exactly what causes a `javax.swing.event.ChangeEvent`, except that it is supposed to be all changes. Without documentation, I was forced to toy around with it to find out just exactly when I could expect to get ChangeEvents, and it turns out … | |
Re: The problem is probably caused by `p + 1` not being a good address for dereferencing. You've assigned `p` using dynamic memory allocation (`new int***`), so I don't know what the next `int***` in memory will be. To be safe, you should probably only perform pointer arithmetic on pointers that … | |
Re: > The string gets passed into the constructer and a file object is made but the file isn't found. If you think the file should be found but it isn't being found then you should print out `f.getAbsolutePath()` which should tell you where the file is supposed to be. Then … | |
Re: You probably want a `java.awt.image.BufferedImage`. It has a method called `getRGB` which can give you the color of any pixel. If you have any other kind of `java.awt.Image` then you can start by constructing a `BufferedImage` of the same size. I'll call it `bImage`. Then you can call `bImage.getGraphics()` to … | |
Re: You declare constants in Java as static final fields such as: package mypackage; public class MyClass { public static final int ID_File1 = 0x6F01; public static final int ID_File2 = 0x6F02; } As long as the fields are public you can access your constants outside of the class, and if … | |
Re: You are looking for `Double.parseDouble(String text)`, a static method of the `java.lang.Double` class, one of the subclasses of `java.lang.Number`. There are many similar methods such as `Integer.parseInt`, `Float.parseFloat`, `Long.parseLong`, and `Byte.parseByte`. They all expect the string that you provide to contain exactly a numeral that you want to convert into … | |
Re: Write a method that rolls two dice and returns the value. Then write a method that does a come out roll and returns a win, a loss, or a point. Then write a method that does an entire game: a come out roll and then repeated rolls until the result … | |
Re: Where did you look to find `%l`? The only place you need to look is also the only place you can depend on for accurate information: http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html I think what you are looking for is `%.2f`, but I should warn you that double is not a good type for representing … | |
Re: if (moveX <= 0 && moveX >= width) { This is only going to test true if `moveX` is exactly `width` (and `width` is zero) or `width` is negative. I'm going to assume that `width` is never negative since widths usually aren't negative. You shouldn't ever depend on a floating … | |
Re: > Any changes to the UI during run time must always be made inside a Thread. This is really bad advice. I hope there are no tutorials on the web making this sort of suggestion. For one thing, anytime you do anything at runtime it must be inside a thread … | |
Re: Finding the sum of all elements of the array is the same as finding the sum of each row, except instead of setting `total` to zero at the start of each row, you don't do that. | |
Re: I think what you want is byte newByte = Byte.parseByte(hex,16); Be aware that I have not tested this. I know what it does in Java, but I haven't tried your C# code, and the meaning of System.Globalization.NumberStyles.HexNumber seems a bit odd. Apparently it "Indicates that the AllowLeadingWhite, AllowTrailingWhite, and AllowHexSpecifier … | |
Re: It seems like you've narrowed down the problem to `dist(controlX, controlY, moveX, moveY) <= rectHori/2 + rectVert/2`, but it's difficult to know for certain if there is a problem there without knowing what `dist` is exactly. Even so, `rectHori/2 + rectVert/2` seems like a strange calculation to be doing. Can … | |
Re: Calling `setVisible(true)` doesn't help for JLabels. They are naturally visible, but only if their parent container is visible, and I can't see where most of your labels are added to a parent container. That's probably a problem. I also notice that you have two JFrames. You have the JFrame called … | |
Re: Add a field that remembers whether last time was a lie. Compare `itsUsersNumber` and `itsSecretNumber` to see if `itsUsersNumber` is too low or two high. If `chance == 1`, the guess is too high, and last time wasn't a lie then lie and record that you lied. Otherwise, show the … | |
Re: The strangest thing about the code you have now is that you are ignoring the return value of getIncome and getExpenses. Based on the names of those methods, people would expect they are invoked mostly for their return value, so it is confusing that you aren't using the return value. … | |
Re: It is also important to know exactly what you want to simulate. When you say "road design" it makes me think you are talking about traffic flow, meaning that if you give the simulator a map of roads including road signs and the number of lanes for each road, and … | |
Re: If you only want the highest palindrome then why are you making a list of all of them? You should just start from the highest palindrome and work downward until you find one that meets your needs, then print that. You could start at 1000000 and work your way down … |
The End.