713 Posted Topics
Re: Do you know about generics? They're a framework for doing what I think you're talking about. Using the standard library implementation of Stack, this line: [CODE]Stack <Card> cards = new Stack<Card>(); [/CODE] will create a Stack of Card objects - if it's not a Card, it won't go on the … | |
![]() | Re: I don't have much patience with the people who insist that there's something not stupid about talking about a total ban on guns in the US, but I get even more sick of the macho posturing from the other side. My feeling is that both extremist positions are basically inane, … |
Re: Prices is an array, not a number. Perhaps you ought to be able to add an array to an integer and get some meaningful number, but in Java it's not so. You need to find a way to tell the compiler what you mean. Presumably, you want the total of … | |
Re: The problem is in line 8, but it's triggered in line 10. For an ArrayList of size n, what is the range of valid indexes? | |
Re: Can you import other util classes? Try java.util.Timer or java.util.ArrayList | |
Re: You want to only accept the inputs "Y" and "N"? One way would be to put the input in a loop, and only break out of the loop when one of those characters is the input. This is a good place to use a switch statement - you'd wrap it … | |
Re: The String class has a charAt() method that might be useful to you. See the String documentation in the Sun API: [url]http://download.oracle.com/javase/6/docs/api/java/lang/String.html[/url] If you're not familiar with those pages, it's the place to look to find out what methods the standard classes have, and what a given method does. While … | |
Re: This is great - the only help you needed was "tell us what the error is" and it looks like you took it from there - and you explained your error nicely, so anyone reading this can get a sense of what was going wrong. | |
Re: This is probably the wrong answer, but if you have this kicking around, could you not just write a "Question" class and an Extractor class that can "AddQuestion", then feed this stuff into an instance of Extractor that you've named "test"? It looks to me like the jvm will parse … | |
Re: Can you make your question a little more clear, please? I don't know what you're asking. | |
Re: Mac's 1.6 is not quite done yet, so definitely stick with 1.4 for compatibility. We had all kinds of trouble with this in a project I worked on last year - for a while, I was coding on a virtual Ubuntu install because I couldn't run the project on my … | |
Re: Well, you're not so much declaring those fields in Employee. Instead, you're taking them in as parameters, and then delegating the work of handling those to the Person class, which knows how to deal with them. So suppose that Person does something fancy with some of those parameters - maybe … | |
Re: Walter - obviously, you've typed this code in and mistyped some things. The variables Tong is pointing to are not declared in this code. However, they would have to be declared in the code you're running, or you would be asking why this program doesn't run. The lines you pull … | |
Re: Hm, two posters from Singapore asking about the same problem set. What are the odds. Good catch, Tong. Hazeel - what you use to solve this sort of problem depends largely on the sort of data you have and how it's defined. If there's a fixed-width format, you can read … | |
Re: I'd be happy to look at this, if you tell me what I'm looking for. What is it doing that it's not supposed to be doing, or not doing that it should be doing? | |
Re: Interesting question. My boss will be annoyed at you. :) I think I understand the problem, but just to be clear, can you show me what the outcome of the transposition would be? I'm not a math guy, so I'm not sure I've got your terminoogy right. Would it be: … | |
Re: The difference between do-while{} and while{} is simply that the while{} evaluates the test condition before the first iteration, and only executes the first time if it's true, where do-while{} executes once before evaluating. I usually avoid do-while{} for readability, because I'm used to finding the loop condition at the … | |
Re: [QUOTE]Wondering which video game system is better for your 8 year-old cousin: Nintendo Wii or XBox? Make a poll. [/QUOTE] TRWTF. (Oh, sorry, different site!) What moron puts their eight year old in front of a "game system"? Might as well lobotomize the poor little twerp and get it over … | |
Re: You're assigning temp to something (no idea what P is, but it's an assignment) in the case that iter ==0. What is temp in the case that iter !=0? I suspect you're declaring temp and not assigning anything to it except on the first time through. | |
Re: Funny, your summary of the assignment suggested to me that you wanted to print out the first 100 numbers that are evenly divided by three -that is, the list [3, 6, 9, 12...294,297,300] Are you sure that's not the assignment? What you're doing is interesting, but I can't imagine anyone … | |
Re: So, NewOrder - what was the problem you were running into? I see a few potential trouble spots, but I'd like to know what question you're asking before I go answering it. :) | |
Re: I've got a question about the logic, before I address the code. For your final outcome, do you want to have the total of "no. students" for each "room"/"index" pair? If not that, what do you want to do with these totals when you get them? Concretely, you say you … | |
Re: Using the reverse method sort of defeats the purpose of the exercise, doesn't it? Unless all you want to do with java is call ready-made methods in the built-in classes, I suppose. | |
Re: You want to extract digits from a string? Well, the most obvious would be a for loop, from 0 to length of string. In the body of the loop, you check each character of the string for digitude. You could write a method to do this (ie, return (c>='0' && … | |
Re: No, it's not the right syntax. You've got an extra assignment in there. Strip out the second d0= and you should be good to go. d0 = (d0 < 3) ? d0 % 10 - 7 : d0 = d0 % 10 + 10 % 7; | |
Re: Excellent article. It might be a little dense for some readers, but it's worth a look. My view of the matter is pretty simple: in most cases, you'll lose more time by confusing the maintenance coder than you will gain by writing an obscure piece of code, even if it … | |
Re: Right now you've got a pretty linear command flow. User comes in at the top, and flows down through the code until they fall out the bottom. You could keep a similar linear flow, and simply loop around back to the case. I always wanted switch statements to have a … | |
Re: I think the confusion is in the suggestion that you find the substrings by position in the string - the data is not fixed-width, and if it were, there's no reason to count on it remaining so, since data formats change. "Why can't we use a two-character value in column … | |
Re: One problem I'm seeing in your demo is that you only create one PalLoc object. Move the new PalLoc() instruction into the for loop, so that you're adding a different object to the arraylist each time. I believe what you're doing here is creating one PalLoc object and then repeatedly … | |
Re: It looks like you calculate the volume correctly in there. From there, the cost should be a piece of cake. What's the specific trouble you're having? Also, I see you're writing the output to a file - is this intentional? Normally, writing this output to the screen would be sufficient. … | |
Re: I'd suggest you use small children to count the coins. They could be fitted with USB ports to make data transfer easier. | |
Re: You're switching on medium, which is 0. You're going to get the default case each time, unless you set medium to a new value, probably derived from user input. Probably easier to extract the first character from the input string and switch on it as a char value, rather than … | |
Re: What are the constraints on the data? Index is always an integer, right? Is your second column always an integer? Does your third column always begin with an alpha character? If so, you should be okay. Read the index. Read the next item. If it's an integer, it's a "no. … | |
Re: Okay, let's see. You want your code to print out, for each number from 1 to 1000, the number of zeros? So, for 1, it would give 0, for 10, it would give 1, for 200, it would give 2, and for 899, it would give 0, and so forth? … | |
Re: Whatever a design pattern is, it's certainly not a product. You can't buy a Singleton. | |
Re: One use for the protected label is for methods of a class that have to be accessible by other members of the package, but you don't want available to classes calling on that. Suppose you have a largish class, and you want to set up a static class with some … | |
Re: Saurav: plese read this, then come back with a question: [url]http://catb.org/~esr/faqs/smart-questions.html[/url] Chaitali, you could also benefit from this. | |
Re: You want to print out and leave the original array unchanged? Use the modulus operator. for (i=0; i<10; i++) { print(array[i+offset] mod 10;} Sorry, that's a left shift. Modify appropriately for right shift - should be easy enough to do. | |
Re: Whoa, cowboy. One homework problem at a time! | |
Re: sos is right here in principle, and you'd probably do well to try to implement it as he suggests. However, I'm guessing this is a first-year class assignment, and maybe you want to keep it simple. Okay, use two switch statements, one on input.charAt(0) and the other on input.charAt(input.length()-1) You … | |
Re: It might be useful if you were to give us some ideas of what you're interested in working on. FOSS development is really a matter of "scratching your own itch" - find something that you think needs to be done, and do it. If you were to tell us what … | |
Re: Wow, a perfect zero of a post. Can we make this a sticky, under the heading "how not to ask for help"? | |
Re: VirtualAsset's defintions are correct. Examples might help, though: "This" would often be used in a constructor or in a setter method. You'll often see it used like this: [CODE] public class MyClass{ String someField; public MyClass(String someField) { this.someField = someField; } public void setSomeField(String somefield) { this.someField = someField; … | |
Re: I think the question is "can one open a file for exclusive access - ie, get an flock - in a java program". Not "can one open a file, for exclusive access by Java" (ie, open a file so only Java can use it). Don't know the answer off the … | |
Re: I've used the same analogy a number of times, Stephen, and I agree with your views on this. vi and a compiler is my development environment of choice. It's funny, I'm just having a similar debate on an Irish music site - there's a really cool piece of software that … | |
Re: First choice would be to clean up your namespace. Do both class and attribute need to have the same name? If so, using the standard capitalization will clear it up: the class would typically be called Width, not width, so there's no conflict. | |
Re: There are two standard printed references on Swing. Both are in the range of 900 pages long and explain Swing quite thoroughly. If you can't get ahold of one of those, there are many on-line tutorials (including ones released by Sun and those made by third-party writers). Sun's on-line documentation … | |
Re: This looks like you're trying to put a constructor for Cell in the DynamicProgramming class. That's not going to work so well. | |
Re: Aditya: The compiler is required to ensure that variables are not unassigned when they are referenced. Since the assignment of i2 occurs within an "if" (and not anywhere else) the compiler assumes that (i1>3) might not always be true, and therefore i2 might sometimes be unassigned. When you declare i1 … | |
Re: The applet security model makes reading and writing pretty difficult. The applet runs in a glass box, basically, and it's a pretty hard job to get it to talk to the outside world. If you just want to pass in data, that can be done, and you can pass out … |
The End.