713 Posted Topics

Member Avatar for comSysStudent

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 …

Member Avatar for comSysStudent
0
140
Member Avatar for diafol
Re: Guns

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, …

Member Avatar for jon.kiparsky
0
661
Member Avatar for kdgeiger

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 …

Member Avatar for kdgeiger
0
203
Member Avatar for Jb2481

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?

Member Avatar for jon.kiparsky
0
754
Member Avatar for therstonsplace
Member Avatar for therstonsplace
0
132
Member Avatar for walter307

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 …

Member Avatar for new_programmer
0
141
Member Avatar for lloydsbackyard

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 …

Member Avatar for jon.kiparsky
0
2K
Member Avatar for comSysStudent

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.

Member Avatar for comSysStudent
0
529
Member Avatar for sadhawan

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 …

Member Avatar for jon.kiparsky
0
179
Member Avatar for sujathaarsid

Can you make your question a little more clear, please? I don't know what you're asking.

Member Avatar for jon.kiparsky
-1
62
Member Avatar for EricTetz

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 …

Member Avatar for jon.kiparsky
0
170
Member Avatar for SeanC

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 …

Member Avatar for jon.kiparsky
0
138
Member Avatar for walter307

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 …

Member Avatar for walter307
0
175
Member Avatar for hazeeel

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 …

Member Avatar for jon.kiparsky
0
623
Member Avatar for dylgod

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?

Member Avatar for jon.kiparsky
0
116
Member Avatar for onako

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: …

Member Avatar for jon.kiparsky
0
110
Member Avatar for NewOrder

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 …

Member Avatar for NewOrder
0
120
Member Avatar for EricMack

[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 …

Member Avatar for EricMack
0
445
Member Avatar for sid.maths

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.

Member Avatar for sid.maths
0
104
Member Avatar for mith_cool

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 …

Member Avatar for javaAddict
0
125
Member Avatar for NewOrder

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. :)

Member Avatar for tong1
0
213
Member Avatar for shahreza

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 …

Member Avatar for shahreza
0
123
Member Avatar for tong1

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.

Member Avatar for tong1
0
157
Member Avatar for jemz

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' && …

Member Avatar for jemz
0
1K
Member Avatar for 0xCMD

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;

Member Avatar for 0xCMD
0
2K
Member Avatar for Spakes

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 …

Member Avatar for jon.kiparsky
0
2K
Member Avatar for caierhui

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 …

Member Avatar for jon.kiparsky
0
748
Member Avatar for jemimaloh

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 …

Member Avatar for jemimaloh
0
2K
Member Avatar for cjmartin

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 …

Member Avatar for NormR1
0
619
Member Avatar for dreamweaver75

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. …

Member Avatar for jon.kiparsky
0
187
Member Avatar for vhea

I'd suggest you use small children to count the coins. They could be fitted with USB ports to make data transfer easier.

Member Avatar for jon.kiparsky
0
146
Member Avatar for dylgod

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 …

Member Avatar for tong1
0
112
Member Avatar for shahreza

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. …

Member Avatar for shahreza
0
197
Member Avatar for rakesh07
Re: java

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? …

Member Avatar for jon.kiparsky
0
111
Member Avatar for prash.study

Whatever a design pattern is, it's certainly not a product. You can't buy a Singleton.

Member Avatar for Zaad
1
142
Member Avatar for SeanC

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 …

Member Avatar for bulger2503
0
126
Member Avatar for sauravmakkar

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.

Member Avatar for NormR1
-2
87
Member Avatar for greenman626

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.

Member Avatar for jon.kiparsky
0
276
Member Avatar for Dokka
Member Avatar for TheComputerGuy

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 …

Member Avatar for TheComputerGuy
0
179
Member Avatar for Unbidden Ghost

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 …

Member Avatar for ~s.o.s~
0
159
Member Avatar for anju soosan

Wow, a perfect zero of a post. Can we make this a sticky, under the heading "how not to ask for help"?

Member Avatar for stephen84s
-1
90
Member Avatar for gabhinav31

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; …

Member Avatar for jon.kiparsky
0
137
Member Avatar for P00dle

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 …

Member Avatar for P00dle
0
112
Member Avatar for ashwiniku

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 …

Member Avatar for jon.kiparsky
0
603
Member Avatar for edup_pt

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.

Member Avatar for edup_pt
0
120
Member Avatar for aryowap

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 …

Member Avatar for jon.kiparsky
0
190
Member Avatar for Sunshineserene

This looks like you're trying to put a constructor for Cell in the DynamicProgramming class. That's not going to work so well.

Member Avatar for WargRider
0
219
Member Avatar for aditya027

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 …

Member Avatar for WargRider
0
132
Member Avatar for abbyo

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 …

Member Avatar for NormR1
0
217

The End.