BestJewSinceJC 700 Posting Maven

Therefore, you have to gather information from the maze as you navigate your way through it.

In any case, you somehow have a representation of a maze. If you figure out a different way [other than using a stack or a queue and the algorithm I suggested] to do this program I'd be very interested to see it. But good luck on your project.

BestJewSinceJC 700 Posting Maven

You need to keep track of the size of your array, then loop over the contents which have been filled, adding them. If it was an array of Objects, and the array was initialized to null (same as Java?), you could also use an if statement such as... if (element != null) total+= element.value;

BestJewSinceJC 700 Posting Maven

Any Object can be inserted into a queue. Think about it logically - a queue is just a collection of items where the first thing put in the queue will be the first thing to come out of the queue. A line at a grocery store is an example of a queue. The first person to get in line is the first person to get out of the line.

BestJewSinceJC 700 Posting Maven

And I quote you the same post I made to you when you posted this exact thread on PFO:

Lol. I coded it already; took me 2 minutes and I don't even know C++. No, but seriously, nobody is going to do your homework for you. This is about as pathetic an attempt as I've ever seen.

BestJewSinceJC 700 Posting Maven

If that explanation didn't make sense, which I doubt it did, use the maze I gave you above and go through the algorithm. The maze I gave you above is small enough to do quickly but it demonstrates what you need to know about the algorithm. Just go through it step by step and you'll understand it by the time you finish the maze. And yes, the algorithm I gave you is definitely correct. Google Maps uses a more sophisticated, but similar, algorithm.

BestJewSinceJC 700 Posting Maven

1. From whatever cell you're at, check the North cell. If you can go there, add it to your list. Check the South cell. If you can go there, add it to your list. Check the East cell. If you can go there, add it to your list. Check the West cell. If you can go there, add it to your list.

After you do that, if your current cell is named currentCell, and you're using an LinkedList called availableCells, do currentCell = availableCells.removeFirst(). In other words, set current cell = the first cell in your availableCells list, and remove the first cell from the availableCells list. Now go back to step 1. and repeat until you find the finish.


And if you don't have a file to read the maze from, then how are you getting the maze?

One more thing - if you still don't understand how the algorithm works, create a small maze and follow its steps. Once you do that you'll definitely understand. Here's an example, where # are walls, x is start space, o is goal space, and * are spaces you can go to.


#####
# x** #
#*#*#
#** o#
#####

Ok. You initially have a queue. Using a LinkedList for the queue, called availableSpots. You also have a currentCell Object which is initially the start cell. Now, doing the algorithm

1. We look at our current cell (the …

BestJewSinceJC 700 Posting Maven

That doesn't make sense. Maintain a sorted linked list by making sure that every time you do an insert, it is inserted in sorted order. No need for a sorting algorithm.

BestJewSinceJC 700 Posting Maven

edit: nvmmm

BestJewSinceJC 700 Posting Maven

Yes, you could do this more easily. As an example,

System.out.println("Here's an example for you. " + num + ", " + (num + 1) + "");

Where I have (num + 1) in parenthesis that lets the compiler know that you're adding with the + sign. Otherwise, the compiler would think you're doing String concatenation. (If you take out the parenthesis there, it will print out 01 because it combined the two Strings).

Also, your problem is confusing to begin with. Like I said, and like the person above me just mentioned, do the numbers have to be in a series? For example what do you want your output to be if the person types in 1 and 5? 1, 2, 3, 5?

BestJewSinceJC 700 Posting Maven

I'm just going to link you to the project that I was given back when I did it. It gives you the exact algorithm; you just need to implement it. My project was somewhat different, but the way that you get from the start to finish of the maze is the exact same.

http://www.csee.umbc.edu/courses/undergraduate/341/fall08/projects/proj2/341-fall08-p2.shtml

Go to the part where it says "the algorithm". If you don't understand why the algorithm is used, then ask me. But I do guarantee you that it works. And it's important to understand why it works correctly, so spend a few minutes trying to figure it out on your own, and then don't hesitate to ask questions if you need to.

BestJewSinceJC 700 Posting Maven

I did a project like this, except with more strict guidelines. What you do is use either a stack or a queue. Push the start space onto the stack/queue. Then, push any adjacent cells (that you can move to!) from the cell you're currently at (at first, this will be the start space). Then, pop a cell from the stack/queue and repeat. You will eventually find the finish. If that didn't make sense, you're basically 'looking' at whatever cell you're currently at, pushing all adjacent cells that you can move to on the stack, popping the next cell from the stack, and repeating until you find the finish.

Good luck...

BestJewSinceJC 700 Posting Maven

Make sure to put break after each part of the switch statement. And the reason it's telling you num1 and num2 are wrong is because you declared them from within one part of the switch statement, but then tried to use them within a different part of the switch statement. That is not allowed. Consider this code:

while(whatever){
int number = 0;
number = 5;
}

System.out.println(number);

That print statement is going to cause an error. By declaring number (where I have int number) inside the while loop, I am giving it a range of that while loop. It can't be used outside of that loop. If I wanted to use it outside of that while loop, it has to be declared outside of that while loop:

int number;

while(whatever){
number = 5;
}

System.out.println(number);

For the code below, which you posted, saying input = in is unnecessary. Just say in.length() like I have below. You could further shorten it into one statement also.

public Postfix(String in) {
    int stackSize = in.length();
    theStack = new Stack(stackSize);
  }

I was going to get you a link to read about scope, but they all overcomplicate it. Basically a variable has the scope of where you declare it. So if you declare a variable in a method, it can be used anywhere within that method. If you declare a variable within a loop within a method, it can only be used within that loop. Etc.

BestJewSinceJC 700 Posting Maven

So the numbers have to be in a continuous sequence? Or is that just a coincidence in the bad example you picked? Because from what you stated, you could just generate four random integers and display them and you're done. Or do two of the numbers have to be the ones the user entered? If so, what do the other numbers have to be... anything, like you said, or some sort of sequence, like your example implied?

Also. . . do your own work. We don't do code for you. Explain your problem better, then attempt to code it on your own. If you have any problems you can ask specific questions that don't say "do this for me", but that say "I need some guidance", and we will answer those. Also, post your code, in code tags.

BestJewSinceJC 700 Posting Maven

Items will be aligned in a container in the order that you add them. So yes, it is possible. Is that what you're asking? If you wanted the button above, just add the button first and add the table second.

BestJewSinceJC 700 Posting Maven

Haha - Touche

BestJewSinceJC 700 Posting Maven

I could be wrong, but I think that is what the sticky at the top of this forum is there for.

;)

http://www.daniweb.com/forums/thread99132.html

BestJewSinceJC 700 Posting Maven
if ((x==0)||(y==0))
            return 1;
       else if ((x==1) || (y==1))
                return 1;

One problem lies in the 'else if' part of that code. If you're on the first step, you still have to go down one. That makes a total of two ways. However, since you said 'return 1', you only account for one of the ways, and prevent the recursive call. (Basically, remove the else if portion, I think your code will work better).. you have two base cases where you should only have one.


Also, in your recursive call, why are you subtracting from both x and y? What do x and y represent? I'm assuming x represents the step you're currently on. If so, what does y represent? And finally, I retract what I said previously about needing a parameter to count the total number of ways. That's already taken care of by "return (numWaysToClimb(x-1,y-2)+numWaysToClimb(x-2,y-1));" (Well, it will be once your code works properly)

Also - I apologize for the conflicting advice (about the second parameter). I'm almost positive what I said in this post is correct. When I get to work in a couple hours, I'll code the solution myself to make sure that it is, in fact, good advice. I'm not going to post the solution because that would destroy the point of learning, but I will give you some hints from there if you need it.

BestJewSinceJC 700 Posting Maven

Sorry.. you'd actually also need a second int parameter to count the total number of ways

BestJewSinceJC 700 Posting Maven

Ok, well why do you need your method to take two parameters? If you're always taking one or two steps, the only parameter you should need is the step you're currently on. Then, at the end of the method, you should have two recursive calls (which you do). The one should try to go down two steps, the other should try to go down one step. If you cannot go down anymore, then you should return 0 for that attempt.

BestJewSinceJC 700 Posting Maven

How could you possibly have the code when the description he gave was very incomplete. Lol.

BestJewSinceJC 700 Posting Maven

4-5
4-5-6
4-3
4-3-2

I count 4 ways. And the number you start at will never matter if I'm doing this correctly, so whats the point? If I'm not doing it correctly than perhaps you should explain.

BestJewSinceJC 700 Posting Maven

newNode.link = top;
top = newNode;


These lines of code don't make sense. Whatever the current 'top' Node is, you should be assigning it's 'next node' pointer to newNode. Since you're keeping it in an array, you could just drop the whole 'linked list' thing and put your stack in the array. It seems you are mixing concepts.

BestJewSinceJC 700 Posting Maven

(only universities can have professors, and those won't touch introductory programming courses)

The second part is false.

And Chico, post your own thread, post what code you've written in code tags, and explain what problem you're having and what part of the code you're having it in.

BestJewSinceJC 700 Posting Maven

An easy way to do this would be to google "Eclipse" and then download the Eclipse editor from their website. It comes with everything else you need (although if you don't know what you need, you should learn what those things are).

BestJewSinceJC 700 Posting Maven

What part of your code isn't working? Your code should be split into pieces/methods that each perform a specific task. You should be able to identify where the code isn't behaving as expected, either with a debugger or just by using print statements. Tell us where your code doesn't work, and we will help you make it work. Asking us to "solve this for you" is ridiculous, especially since very few of us actually know what magic squares is.

BestJewSinceJC 700 Posting Maven

Make the changes that Ezzaral suggested, then re-post your code. You are more than likely just missing a closing brace somewhere. For every opening { brace, you need a closing } one.

BestJewSinceJC 700 Posting Maven

You should probably have code where you catch the Exception. No use catching it if you don't know when you caught it. And the question of where to put the Thread.sleep() call depends on where you want the pause to be. Right after you have executed all the code that displays whatever you want to display, put the Thread.sleep there. Also, the problem is probably that you have Thread.sleep(200). That is a pause of 200 milliseconds, or 1/5 of a second. Try putting Thread.sleep(2000) - you may notice a change.

BestJewSinceJC 700 Posting Maven

So you have multiple stacks, then. What I said still applies... you're either not allocating enough space or you're trying to put something in the array at the wrong index. You might want to also check that you actually allocated the space to begin with and that the array isn't null.

BestJewSinceJC 700 Posting Maven

If you expect a solution, please post the exact error code you are getting. It usually includes line numbers and method names, etc.

BestJewSinceJC 700 Posting Maven

If you want to parse a String into Integers, use the method Integer.parseInt(stringParseableAsIntHere). If you're sending the String to a char array, you could use the " + " operator and "" to put it back as a String and use the parseInt method.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

I think there is a method, Thread.getCurrentThread() ...

BestJewSinceJC 700 Posting Maven

Look at the Java Sun tutorial on ActionEvents and ActionListener. They have all the examples you need as well. I was able to learn all about them by myself, and so will you, if you read. If you have any specific questions, ask those...

BestJewSinceJC 700 Posting Maven

So what is your definition of a subsequence? I still don't understand what you are saying at all.

BestJewSinceJC 700 Posting Maven

Your code in "push" takes two arguments: An integer representing the index you're "pushing" the item onto, and the item that you want to push onto the stack. You got the Exception because you tried to push an item onto the stack at index = 3, but the array is too small; therefore, you can't push anything onto index 3 since it doesn't have 3 indexes.

Why do you need to give the 'push' method an index, anyway? Instead, you could have a variable 'currentSize' in the MStack class that keeps track of how large your stack is. Then, in your push() method, you'd just automatically add the new item onto the end and increment the 'currentSize' variable.

A possible problem: Since you are using an array, and not an Arraylist, you need to make sure that you allocate enough space (make the array big enough) to begin with. Otherwise, at some point, you might get an ArrayIndexOutOfBoundsException. If your array reaches it's maximum size (or at some point before it reaches its max size), you will have to make a new array which has a bigger size and copy the old one over to it. So somehow you're either not making your array big enough or you're calculating the wrong index (that you pass to the push method).

BestJewSinceJC 700 Posting Maven

What error are you getting? Where do you need help? Can you identify any portion of your code that isn't working as you expect it to? If so, how do you expect it to work?

If you can't answer these questions, don't bother posting a question on this site because nobody cares and nobody is going to read your entire project description to help you. (But if your teacher does a quick google search, you just got a 0). The question I bolded is perhaps the most important, because if you can't do so, then you either

A) haven't written enough code to come across any that isn't working
B) didn't make any effort in helping yourself, so why should we help you?

BestJewSinceJC 700 Posting Maven

Can you post the error you are getting? It should include the line number, method names, and error name... info that would be incredibly helpful in helping you.

BestJewSinceJC 700 Posting Maven

See this http://www.daniweb.com/forums/announcement9-2.html

And your directions say to make it 'trivial to implement other letters' but I'm not sure how trivial it can be to do print output like this. It's not that difficult, but it was always aggravating to me. A relatively easy way to do this might be to make an Object called letter and have variables for Letter such as height and an array that defines how many #'s are on each line and if there are spaces between #'s on a given line, how many spaces there are. The need for this being that if you were to just print out the letters individually, they would not show up next to each other.

Maybe someone here has a better suggestion than that which can 'put the letters next to each other' but I don't think that one exists. You just have to work around it, printing out all the highest level characters first, I think.

I'm assuming this is the problem you are facing, but perhaps you are simply too lazy to do it on your own. If it's the first... elaborate, explain your difficulties, and show what effort you've made.

BestJewSinceJC 700 Posting Maven

You can't instantiate a 'Blob'. According to the API, it is an interface. You can, however, instantiate SerialBlob.

BestJewSinceJC 700 Posting Maven

Post the code in code tags that you think is incorrect, or at least post the compiler errors you are getting.

BestJewSinceJC 700 Posting Maven

Use code tags.

system.out.println("You entered a wrong month");
Should say: [B]S[/B]ystem.out.println ....

And in at least one spot that I noticed, you're using "=" to compare things, when you should be using "==". One equals is used for assignment (to set day = today; for example), two equals are used for comparison, does today == tomorrow for example.

Also, copy and paste the full compiler error to us, so that we can help you better. I don't see anywhere where you're missing a ';'. It could be because of your other errors, though, so fix those first.

BestJewSinceJC 700 Posting Maven

This might also be useful to you, as it gives greater control than most of the other layout managers. But I'm not sure why setSize isn't working... post your code? http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html

BestJewSinceJC 700 Posting Maven

And my point is that Dijkstra's algorithm does not *know* how many edges are on the path until it is finished, so modifying it would not make sense. Am I wrong?

BestJewSinceJC 700 Posting Maven

Another thing, that isn't the source of your problem... you might need to have a different Object for each layout. You're using the same 'cards' GridLayout for both. I'm not really sure about that but I typically see a different one for each panel. (Someone confirm or deny that?)

BestJewSinceJC 700 Posting Maven

Dijkstra's algorithm would not be easy to modify, I don't think. . if you do the algorithm on paper, you end up with a 'trail' of visited Nodes in your shortest path. This means that when you program it, you're essentially keeping track of each Node on the shortest path. But if I remember correctly, you're not keeping track of anything else: for example, alternate paths. So you'd have to rewrite the entire algorithm in order to make it consider your edge limit, making it useless.

BestJewSinceJC 700 Posting Maven

It's not necessarily better style/design. And if the job of one function requires another function, then you should call the other function within the first function. You shouldn't use main to do it. And I'm kind of curious how to do this as well, which is why I am upping this topic. Its been a while since I've programmed in C, but I would think you'd just include the one header in the other one. Since you need to compile each file into a .o, I'm not sure where that comes into play though. Guess you'd just always have to link them somehow.

BestJewSinceJC 700 Posting Maven

Well, just for the hell of it, I'm going to write a Sudoku program also. It might take me a few days since I have other things to do this week and I don't know how to play the game yet. Lol. Could you post your input that's taking a long time to run? Also, I'm not sure I understand how you're getting input to begin with. Unless you redirected stdin to a file, it looks like its from the keyboard.


edit: Also, you realize you can probably find hundreds of Suduko programs written in Java online, right?

second edit: After some initial reading, this looks like it is going to be harder than I thought... you're definitely better off getting help by searching the web for some better algorithms than waiting on me. And I don't understand how your code works either... does it work correctly (on smaller puzzles)?

edit (yet again :) ):
Are you using a brute force algorithm to solve this? Such as http://decibel.ni.com/content/docs/DOC-2391

BestJewSinceJC 700 Posting Maven

http://java.sun.com/javase/6/docs/api/java/lang/SecurityManager.html#checkDelete(java.lang.String)

That might be of interest to you. I'm pretty sure if there is some security measure, you aren't going to be allowed to delete the file. That is, after all, the point... right?

BestJewSinceJC 700 Posting Maven

While statics can be "nice" in some cases, they should generally be reserved for constants and stateless utility methods. Using them to share state can cause all kinds of headaches further down the road. I'd recommend reading through some of this discussion:GlobalVariablesAreBad and perhaps some of this one: SingletonGlobalProblems as well.

I'll check those articles out, but my first thought is just because something can be dangerous doesn't mean it shouldn't be used. I also haven't had any serious trouble with statics. But maybe I'll change my opinion after reading.

edit: Read the whole first article, skimmed through some of the second. There are some good points there, some of which I have heard before. But I still think (despite the list of 'bad uses of globals' in the first article) that Peter's solution to use a static method and static variable is just as good passing the Object around to every place that he needs it, although I'm less sure of that now.

BestJewSinceJC 700 Posting Maven

If your class that you're making an ArrayList of is called Supplier, write a toString method in the Supplier class. The toString method should return a String that contains all the information (name, etc) for a Supplier. Then, for each Supplier in the ArrayList, do yourTextArea.append(Supplier.toString())