BestJewSinceJC 700 Posting Maven

Figure out the maximum number of exchanges that can take place in the MAX_HEAPIFY routine. Figure out the max number of times it can be recursively called (Ex: lgn), then multiply those two numbers and you have your answer.

BestJewSinceJC 700 Posting Maven

I really don't understand what you are saying. How would I initialize "phrase" if i put

while (!phrase.equals("quit")) {

so soon? I'm really new with java so please be kind to me.

Phrase is initialized in the code that you posted. It is initialized to "", which is the empty String. In order to quit using the code Masijade showed you, after you say "please enter a sentence or phrase" inside of the while loop, you would need to read in the user's input, then store it into the phrase variable. If that doesn't make sense, then read about the Scanner class. http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

Relevant topics: Where it says,

For example, this code allows a user to read a number from System.in:

Scanner sc = new Scanner(System.in);
int i = sc.nextInt();

But you cannot read in Strings with the nextInt method, so read about the nextLine() method.

BestJewSinceJC 700 Posting Maven

Nope. Read the rules.

BestJewSinceJC 700 Posting Maven

Your syntax is wrong, that is all. .

if ((myStack.empty()==true) && (line.charAt(j) == ')')||(line.charAt(j) == ']')||(line.charAt(j) == '}')) {

Should be:

if ((myStack.empty()==true) && ((line.charAt(j) == ')')||(line.charAt(j) == ']')||(line.charAt(j) == '}'))) {

Because you want to check "if the stack is empty and any one of }, ], or ) is seen, then . . ." but look at your if statement more closely: It will be executed any time a ']' or a '}' is seen, or whenever both the stack is empty and a ')' is seen.

And haha, your error is ironic if that is it, considering the project assignment is about grouping of operators, which was the cause of your error. (But no offense, I've made similar mistakes before)

:)

BestJewSinceJC 700 Posting Maven

keyword - *generally*, i guess you get the special treatment

He's a sponsor. As an admin, it makes sense to give sponsors little things like that.

BestJewSinceJC 700 Posting Maven

I updated my last post, you should take a look. And at this point, I'd recommend that you first develop the code for the parentheses then. After you get that working, then add in logic for the brackets and curly braces. It would be pointless to help you complete the separate stacks solution, since the algorithm itself is flawed.

BestJewSinceJC 700 Posting Maven

You can't use three separate stacks because consider the following input:

{(})

That input isn't valid, and should result in an error. But if you use separate stacks for each symbol, it will appear legitimate and it won't cause an error. And I'll take a look at your code momentarily.

edit: It looks like you're using separate stacks, which I do not think is correct for the reason I listed above. The order in which the braces/brackets/parens are seen is very important, and using different stacks does not keep track of the order they were seen in. You should implement one stack where you use a few comparisons to make sure things are valid.

You'd have the following comparisons:
1) the case where you just saw a }. You'd have code similar to this pseudocode:

typeOfBrace = readInNextBrace();
if (typeOfBrace == '}' or typeOfBrace == ')' or typeOfBrace == ']') //You have to make sure its a closed type before you pop.
topElement = stack.pop();

if (typeOfBrace == '}'){
if (topElement == '{') // there's no error!
} else //there's an error, do something!

2) the case where you just saw a ]. Pseudocode:

typeOfBrace = readInNextBrace();
if (typeOfBrace == '}' or typeOfBrace == ')' or typeOfBrace == ']') //You have to make sure its a closed type before you pop.
topElement = stack.pop();

if (typeOfBrace == ']'){
if (topElement == '[') // there's no error!
} else //there's an error, do something!
BestJewSinceJC 700 Posting Maven
AccountRecord record[] = new AccountRecord[4];

You created an empty array with 4 elements. Each of those elements is by default null. Then you said:

currentAccount.setAccount(old.nextInt() );

Which attempts to call a method on 'currentAccount', which is an AccountRecord from the array record[] (that you declared earlier). Therefore currentAccount is 'null' and you cannot call a method on something which is null. The correct way to populate the record[] array would be to use a for loop and in the for loop create a

new AccountRecord();

and then set record = new AccountRecord(). Basically I'm saying you need to use a constructor to make a new object, then put that object into the array.

BestJewSinceJC 700 Posting Maven


What if there are say three left parentheses on the stack, but then a right bracket appears? How would the program know that the bracket doesn't match, since there are only parentheses on the stack?

edit: If a closed bracket is encountered when a '(' is on the top of the stack, then you know already that you have an error. So when you see a '}', you should attempt to pop a '{' off of the top of the stack. If the element on top of the stack is not a '{', then you have an error. (If this doesn't make sense, read the rest of my post first, then re-read this).

Should each character be tested every time to see if it's a "closer" and if it matches with whatever "opener" is on top of the stack?

When you see an open bracket, you should push an open bracket onto the stack. When you see a closed bracket, you should pop an open bracket from the stack. If you see a closed bracket, and there are no open brackets left on the stack, then you have just encountered an error. After analyzing an entire set of brackets, your stack should be empty, indicating that the same number of open and closed brackets were seen, in an acceptable order. (For example, {{}}}{ has three open brackets and three closed brackets, but it is not in an acceptable order. If your program encountered {{}}}{ it should do …

BestJewSinceJC 700 Posting Maven

You can't put Strings into an integer array. Create a String array instead.

BestJewSinceJC 700 Posting Maven

paste us the error message. the line that the error occurred on would be good information to know.

BestJewSinceJC 700 Posting Maven

Design an application that accepts reader data and produces a count of readers by age groups as follows: under 20, 20-29, 30-39, 40-49, 50 and older."

Essentially these are your requirements and the rest of the paragraph didn't matter whatsoever. I don't really see how we can help without designing the algorithm for you, but as a hint, consider that you only need to do these things:

1. create an array of size 5, one for each of your age groups, anmd initialize each index of the array to 0.
2. read in data and based on what age group each piece of data fits into, add one to the appropriate array index.

BestJewSinceJC 700 Posting Maven

You can use a package that includes all of your essential classes and just import that package into any class where you want to use those classes. So basically, if you wanted to import the popular File class, you would use import java.io.File; but if you wanted to import the whole package you could say import java.io.*;

BestJewSinceJC 700 Posting Maven

Just some thoughts. .

1) because with the 1/2 condition, if you downsize the array, it will be much more likely that you will then have to subsequently resize the array later (due to having more elements than can fit in the new array you created in contractStack).
2) You should also consider that if you downsize the array based on the < 1/2 condition, then you will be resizing the array more often than you would be with the < 1/4 condition.

BestJewSinceJC 700 Posting Maven

You don't need to repaint() for setting buttons enabled or disabled.

if(owned >= 0)
{
Sell.setEnabled (true);
}

if(owned <= 0)
{
Sell.setEnabled (false);
}

You need to consider the case when owned is equal to 0. If owned = 0, then both of your if statements are going to get executed which might be a source of error. Is it?

BestJewSinceJC 700 Posting Maven

Hints:

for (the number of lines you are given to print){
-print a newline.
for (the number of asteriks per line){
-print one asterik. Do not print a newline.
}


You can do printing using System.out.println and System.out.print. The former will print a newline (same as hitting enter basically) and the latter will not print a newline.
}

BestJewSinceJC 700 Posting Maven

If you want to talk about your lab you're probably better off meeting with your teacher or TA than discussing it here. But if you're going to discuss it here, post the problem and ask specific questions about what you don't understand so that anyone on the site can help you.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

Coffee, all day, a whole pot.

The only real American food is corn dishes.

I think, I'm going to be real American, today, and break-out the corncob pipe.

If a big, fat, juicy hamburger isn't American then I don't know what is.

BestJewSinceJC 700 Posting Maven
if(copy[0]==null) System.out.println("DEBUGGING IS IMPORTANT");

Put that in your readFile method before the while loop.

BestJewSinceJC 700 Posting Maven

And the thing I don't really get is here in TCPEchoClient.c:

while (totalBytesRcvd < echoStringLen)
{
    /* Receive up to the buffer size (minus 1 to leave space for
       a null terminator) bytes from the sender */
    if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0)
        DieWithError("recv() failed or connection closed prematurely");
    totalBytesRcvd += bytesRcvd;   /* Keep tally of total bytes */
    echoBuffer[bytesRcvd] = '\0';  /* Terminate the string! */
    printf("%s", echoBuffer);      /* Print the echo buffer */
}

Why did he use a while loop for this? Wouldn't you recieve the same data by just using

if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0)
        DieWithError("recv() failed or connection closed prematurely"); 

In the project I'm doing, I don't really know how long the string I will be recieving is....

To follow that with another question, if you remove the while statement, what happens if the amount of information you receive exceeds the buffer size? Even from the author's comments, it looks like it will successfully store up to the buffer size amount of bytes, but then, you would not read in the rest of the data. So I'm assuming that the reason for the while loop is to ensure that all of the data is read in - even if it exceeds the size of the buffer. But what do I know, I'm honestly surprised they even let me post in the C forum anymore.

BestJewSinceJC 700 Posting Maven
for (int counter2 = 0; counter2 <= 60;)
{
pressureSum += pressure[Index];
pressureAverage = pressureAverage/58;
counter2++;
}

Should be

for (int counter2 = 0; counter2 <= 60; counter2++)
{
pressureSum += pressure[Index];
pressureAverage = pressureAverage/58;
}

And the main problem is that nobody is helping because you didn't mentioned exactly what isn't working or where your errors are, or what you are even trying to do at this point, or anything specific that you need help with. I'd love to help but I don't really know what you're having trouble with. Specifics.

BestJewSinceJC 700 Posting Maven

Read this entire thread. Since that is obviously the topic. If you want examples of algorithms and their analysis, there are plenty on the internet. Google.

BestJewSinceJC 700 Posting Maven

can someone remind me how to loop a character please. I'm begging you all.

my output must be this:

***********************************************
*                                                                                          *
*                                                                                          *
*                                                                                          *
*                                                                                          *
***********************************************

i know how to set the color attribute for a character, my problem is I for got now on how to repeat the character by looping

to make it proven that It's not a copy paste from some where... I have the color palette here, the cursor position and and the repeatition of the color palette expansion

mov ah, 02
mov dh, 03h
mov dl, 01h
int 10h

mov ah,09h
mov bl,2fh
mov cx, 7
int 10h

can some one tell me to remeber what should be added in looping a character

A jmp statement?

http://www.geocities.com/SiliconValley/Park/3230/x86asm/asml1006.html

BestJewSinceJC 700 Posting Maven

Si. Es muy delicioso. Quiero ir a Nicaragua degustar la comida.

BestJewSinceJC 700 Posting Maven

ما هو معنى تقدير برنامج كمبيوتر

I quite agree. Very strongly worded.

BestJewSinceJC 700 Posting Maven

now i am trying to get my wind speeds, out them into categorys, and calculate the average category.

So it seems like you have your steps figured out. It looks like you got your wind speeds, put them into their categories. . but did not calculate the average. The formula to calculate the average should be something like this:

[ Category (Ex: 5) * number of items in that category ] + [ Next Category * Number of items in that category ] . . . / total items

Although, in my opinion, that kind of algorithm is pretty pointless anyway. The better way to do it would be to add up all of the wind speeds, divide by the total number of hurricanes, then see what category that speed fits into. Whatever category it fits in is the average category.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#renderer


You said javadocs.. have you looked at the swing tutorials though? Using a custom renderer for a JList is done the same way as using one for a combo box, according to those tutorials. I haven't personally attempted it though, and I never will. If you can get the job done with the tools they provide, it is advisable. good luck though.

BestJewSinceJC 700 Posting Maven

Well, for starters you could mark previous threads solved if you no longer have questions/are satisfied with the help you got. Some of these threads look like they are solved; if they are, then mark them as solved.

http://www.daniweb.com/forums/thread230080.html
http://www.daniweb.com/forums/thread229863.html
http://www.daniweb.com/forums/thread229842.html
http://www.daniweb.com/forums/thread229265.html

As for your question, it looks like you already almost have your withdraw method written. Since all a withdrawal does is changes your balance:

public double withdrawCalculuation() {
return balance - withdraw;
}

You could write a method called doWithdrawal that calls withdrawCalculation and sets the balance to whatever withdrawCalculation returns. Of course, your doWithdrawal method would assume that the 'withdraw' variable has already been set to the withdrawal amount (otherwise withdrawCalculation will not work properly). Also, you misspelled calculation in your method name.

BestJewSinceJC 700 Posting Maven

Not that the OP is interested, but in case anyone is, finding the minimum and then finding the maximum takes (n-1) comparisons each for a total of 2n-1 comparisons. The same can be done in about 3n/2 comparisons by doing both at once using pair comparisons.

pair comparisons

Jocamps commented: good point! this is how i would do it anyway :) +3
BestJewSinceJC 700 Posting Maven

Tabemono daisuki.

BestJewSinceJC 700 Posting Maven

Me encanta comer.

BestJewSinceJC 700 Posting Maven

Haha. Pretty amusing that two people from the exact same class ended up here, assuming that is really the case. Apologize for freeposting/upping this thread but that is really funny.

BestJewSinceJC 700 Posting Maven

I have never done it before. but i know this guy who has whom i have no idea where he is now. but he uploaded this harmless virus into the Talk website and crashed it. all the Letters and words came out looking like Arabic or something ?????? very odd. so the webmaster had to shut down the site. couldn't fix it or anything.. it was awful. do you know how to do it ???

Nobody here is going to help you hack a website. Most people here including myself have never attempted such a thing and therefore could not help if we wanted to.

BestJewSinceJC 700 Posting Maven

I see that button_name.setSelected(false) works for checkboxes, but not for radio buttons.
Is there no way to reset radio buttons to an empty set or does it need to be written so that it somehow changes to a default button?

The best way is to read the documentation. That way, you can learn to code on your own rather than needing to ask for things like that. I'm not saying that because I'm mad because you asked, or anything like that, but because reading the documentation for these kinds of issues is simple and is useful to be able to do.

Here you can find info about JRadioButton and how to use it.
http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#buttongroup

Here you can find the API doc for JRadioButton
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JRadioButton.html

As for your segment of code that you posted above, are you sure that you can add an ImageIcon to a JPanel? Because I don't see any methods for doing so. I'm not saying it's impossible, but where is the "add" constructor that takes an ImageIcon? All of JPanel's add constructors take Components. Since an ImageIcon is not a Component, I don't think that will work.

http://www.java2s.com/Tutorial/Java/0261__2D-Graphics/LoadimagetoImageIconandaddittoPanel.htm

BestJewSinceJC 700 Posting Maven

Data Structures and Algorithm Analysis by Mark Allen Weiss

Agreed, that book is crap. I used his Java book w/ the same title in my data structs class.

BestJewSinceJC 700 Posting Maven

For humanity's sake, I hope this Janiceps guy is some random dude messing around rather than expecting answers or actually wanting to do what he's saying.

BestJewSinceJC 700 Posting Maven

checkButton.setSelected(false); should work. In any case there are javadocs for all these things. Type the class name into google, click the javadoc, and read about the methods.

BestJewSinceJC 700 Posting Maven

Learning daniweb's posting guidelines is useful to your major? What about reading comprehension?

BestJewSinceJC 700 Posting Maven

edit: nvm, comment I was responding to was in response to one post in particular

BestJewSinceJC 700 Posting Maven

You need to post your other classes.

firstLevel.add(mainpanel, BorderLayout.CENTER);
firstLevel.add(listpanel, BorderLayout.CENTER);

Looks to me like you're just adding one thing right on top of another. How do you expect to see both?

And there is no sign of CardLayout ever being used in your code. If you want to use CardLayout, that's fine, but I'm not sure how to help when none of your Panels use it. Btw, you don't need to use it anyway. You can just as easily add one "level" to your game at once, and then remove it & add the next level when it is time to do so.

I wish I could be more helpful, but since I cannot run your code and you posted a very minimum selection of code, the best I can say is that I'd simply add the panel that contained the current level, then remove it and add the next level's panel when it was time.

BestJewSinceJC 700 Posting Maven

Lol. Soo much irony.

http://www.mac-sucks.com/switch_why.php

[professional googler/internets troller]

http://themacsucks.com/

BestJewSinceJC 700 Posting Maven

What is the prize for doing your homework?

I'll give you low rep

:)

BestJewSinceJC 700 Posting Maven

Java, because since I am already reasonably good at it, I'd like to become expert.

BestJewSinceJC 700 Posting Maven

Never use CVS. Don't even mention CVS. Usually, don't use SVN either; it's easier to setup something like git or hg and they're better in most ways, but it depends.

SVN I liked pretty well, but I agree with CVS. We were forced to use it for school one semester, and I used it without problems. The next semester, I helped a friend use it who didn't understand it. I locked him out of his own repository, giving an error that I couldn't resolve. It basically said another user had locked the resources, yet it was a one person project. . so there was nobody else who could lock the resources. Turns out a lot of his classmates experienced the same error and the professors just granted extensions.

BestJewSinceJC 700 Posting Maven

PoNoN1=N1+"(POSITIVE)";

You declared PoNoN1 as int, but you probably wanted String.

ps: Java convention is the start all variable names with a lower case letter.

Also, sorry James for posting at the same time as you, but haha @ both mentioning the atrocious variable names.

Oh, and @ OP:

I fixed your program in my editor real quick, and I noticed that you still have another error:

"Product :" + product + productStr;

That isn't going to work. productStr already contains "product" in it, so you're going to get double the numbers in your result that you actually want to be there. You can just use

"Product :" + product;
BestJewSinceJC 700 Posting Maven

edit - sorry, posted this at the same time as James

int N1, N2, product, PoNoN1, PoNoN2;
PoNoN1=N1+"(POSITIVE)";

You can't store Strings into integers. So declare PoNoN2 as a String, not as an integer. Otherwise use a completely different variable. You have many similar mistakes in your code.

String PoNoN1;
PoNoN1= N1+"(POSITIVE)";

Also, your question didn't make any sense to me. Try to be clear about what you want your program to do, what it is doing, and where you think the problems are in your code. If you can't identify problems in your code, at least paste us some error messages from the compiler, or say where you think trouble might lie, or what you don't understand, etc. Also, name variables according to convention. PoNoN2 is definitely not a good variable name.

BestJewSinceJC 700 Posting Maven

We can't help you without seeing the code. Just post it in code tags. And try to ask some specific questions or tell us exactly what you are trying to accomplish and why it is difficult for you.

BestJewSinceJC 700 Posting Maven

The main reason to use pass by reference is to be able to access the original object so that it will still be modified when you leave the function. Right? (Not the best wording, but hopefully what I mean is clear). I see other statements in here that don't make sense to me.

BestJewSinceJC 700 Posting Maven

Yeah, I'm hacking in right now. Give me a few minutes and your IP will be unblocked.