BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

No problem but just letting you know: your way sounds like it could easily lead to errors, and it is logically unnecessary. The way I suggested would allow you to do everything you mentioned, with no extra Threads. In fact, you'd barely have to change anything, since you presumably already have a method created which handles adding/removing all the buttons and such when the turn switches.

One more note; I think you can set JButtons to invisible with setVisible(false) but I'm not positive. But if so, doing so would be better than removing them from the UI completely.

BestJewSinceJC 700 Posting Maven

If you want a serious suggestion, choose a simpler program to break down. If you don't know Java programming, which you clearly don't, then don't try to write about a program that is above a beginner level, for the same reason that you wouldn't try to explain Calculus to anyone without first understanding algebra. For the same reason, you would be wise to choose a program that comes with a description. For example, if you choose a common school project such as a "Java library", you will be able to analyze it more easily because you'll know what it is supposed to be doing and it'll be easier to connect the dots. My two cents: start over. You'll save time in the long run. If you need help choosing a sensible project for your experience level, there are a lot of current and former students here who I'm sure would be willing to help. . I could give you suggestions for programs of similar length (100 lines) that do tasks which I feel are more sensible for you to analyze. (P.S. does anyone else agree/disagree with my suggestion?)

BestJewSinceJC 700 Posting Maven

Interesting. Guess that's it then.

BestJewSinceJC 700 Posting Maven

Change your program so that instead of doing something like getHumanAction, you simply don't do anything until the player takes an action. In other words, if you have a listener that does the getHumanAction when the player clicks his button, then your game will work fine. For example, write an action listener for your buttons. Once you correctly write the action listener for your buttons, when the player clicks the button, the actionPerformed method is called, and you can then do something from within that method. So basically, instead of using getHumanAction to wait for a human action, you can wait for a human action simply by doing nothing until actionPerformed is called. Then, from within actionPerformed, you can do whatever is necessary to continue the game. (Like take the player's turn, then call whatever method takes the computer's turn).

If that didn't make sense, hopefully this small program (not written with absolutely correct code, I'm just demonstrating here) will help:

public static void main(String[] args){
//set up JFrame and JPanels or whatever else is on the GUI here
//Computer goes first (in my example anyway)
takeComputerTurn();

//Now add the buttons onto the GUI so the user can go
JButton button = new JButton("Click to take your turn!");
button.addActionListener(new ActionListener(){

actionPerformed(Event e){
takePlayerTurn(); //player just went since to get in this method, they had to click the button!
}

});
}

Hastily thrown together example but I hope that clarifies somewhat. If not, feel free to …

BestJewSinceJC 700 Posting Maven

Do you want it to be a "random" problem or do you want it to be a problem that you made up in advance, chosen from a list? I'm not going to waste time explaining how to do both when you only need one or the other, so tell us which it is.

BestJewSinceJC 700 Posting Maven

Yeah you've been taught wrong. You have to learn objective c among other tools. This (from my class) is a good reference material:

http://cs491f09.wordpress.com/category/lectures/

But if you have any more questions about the iphone and objective c, etc, post them in the appropriate forum (which I think would be 'other languages' unless you have more questions about Java & the iphone)

BestJewSinceJC 700 Posting Maven

If you're only adding .1 or .25 etc, but the result shows up as something which isn't a multiple of .1 or .25, then y was clearly not equal to a multiple of .1 or .25 to begin with. In other words your initial y value must have been something weird; how was y initially set?

BestJewSinceJC 700 Posting Maven

If "x" is declared as an int variable (which it seems to be) then of course you can pass it to your setX method. You can pass any int variable to a method declared as taking an int. Did I misunderstand your question?

PS if you are waiting for a key to be pressed in order to add to X's value, then you can implement Swing's KeyListener class I think, but it's been a while since I've looked at that.

BestJewSinceJC 700 Posting Maven

If you declare a method as taking an int as a parameter, then you need to pass that int. i.e. in your setX and setY methods, you cannot call setX(), you have to call setX(PUTANINTHERE!!!)

hope that helps.

And one more thing - having getX and getY methods might not be helpful, unless you are returning random x and y positions. If you are actually getting the position of a mouse click or something of that nature, Swing's MouseListener class (and corresponding tutorial) will be helpful. You should start by just writing a client/server pair where the client can send the server the x and y position. Then add on another client, one by one.

BestJewSinceJC 700 Posting Maven

If you want to output in a Swing GUI (which is what you're currently using) in a table format, then you should use a JTable, not whatever else you're using (JTextArea?). Check this out:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

BestJewSinceJC 700 Posting Maven

Umm I might be confused but I just got three PMs from you (posted above me) and you just reiterated what two previous posters in here have already said. Was that really necessary?

BestJewSinceJC 700 Posting Maven

My point was that there is nothing personal about an "average" salary. That is why its called an average, because it includes everyone. Either way, congrats on the scholarship though.

BestJewSinceJC 700 Posting Maven

for count= 1 to 50
display count
End for

int count = 1;
while count < 51{
    display count;
    count = count + 1;
}
BestJewSinceJC 700 Posting Maven

Hey thinkersgroup, they're all taken right now - the rest of us posted about this years ago...

BestJewSinceJC 700 Posting Maven

what is S and what is P? Is that a new question?

BestJewSinceJC 700 Posting Maven

This is definitely interesting. Before I get into my crazy idea of how to do this (that involves bit stuffing and using a special character to denote the start and end of images) let me make sure I understand the issues. Mixing images and text is never really done in the same file, and I don't think there are any 'standard' ways to do this. Do you plan to read back in the images and Strings properly later? Because if you just start writing them to a file together how will you know which is which? You need some way to denote where an image starts and ends. I hardly think writing both to the same file is your issue - being able to read them back in correctly later is your real problem. Yes/no? And any other more intelligent members here have any suggestions? (Before I go off on a tangent about bit stuffing, because there is probably a much easier way to do this?)

BestJewSinceJC 700 Posting Maven

Why is there so much code in your remove method? All you need to do is search linearly through your array looking for an item with the name that matches the String you're searching for. That should take maybe three lines or so of code.

method remove(string removeMe)
for (every element in the array)
if (current element isEqualTo removeMe)
then remove the current element from the array

BestJewSinceJC 700 Posting Maven

You could also (more correctly) fix it by using error checking. try... catch. Exception handling. Look them up. The poster above me, his solution won't work if a user goes back and edits something into a text field that isn't a double. Then you'll get the error again. Error checking will always work.

BestJewSinceJC 700 Posting Maven

An API just defines what kind of functions you can use. Sometimes these just do something like allow you to write a GUI in Swing and sometimes it would allow you to do stuff like gusano mentioned with uploading on flikr.

BestJewSinceJC 700 Posting Maven

Anything that is an Object... is an Object so make it a class.

Science Fiction, Non Fiction, Literary Fiction, and Crime Fiction are dead give aways that your teacher wants you to make them types (either Abstract classes or just a class where everything in that genre extends from it). And of course Science Fiction, Non Fiction, etc should all extend Book because they are all Books. Book, being your most generic class, should in some way be the ancestor of everything else. I'll leave it to you to work the rest out.

BestJewSinceJC 700 Posting Maven

Yeah, TBH you could answer all of these questions yourself without too much trouble. I don't understand why the average salary is a question though - just look it up. More than likely whoever you are asking won't know as well as the internet anyway.

BestJewSinceJC 700 Posting Maven

A brief explanation and example of polymorphism (definition from wikipedia, which btw, seems to only have part of the definition correct, and seems to combine the definition of 'inheritance' with polymorphism. But I think this bit is particularly good):

The primary usage of polymorphism is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time (this is called late binding or dynamic binding).

This just says that you can make an array of Ships, and put anything that extends Ship into that array. Later on in your program, you can say myShipArray[anyIndex].anyMethodShipHas() and it will, with late binding, determine which class's method to call (so it will call CargoShip's method if the Ship is a CargoShip).


hope that is helpful.

BestJewSinceJC 700 Posting Maven

Assign various Ship, CruiseShip, and CargoShip objects to the array elements.

Your program isn't correct; the teacher is trying to demonstrate a concept called Polymorphism to you. Essentially you should be creating Ships like this:

#
Ship[] types = new Ship[6];
types[0] = new CargoShip();
types[1] = new CruiseShip();
types[2] = new Ship();
types[3] = new OtherKindOfShip();

Also, I noticed you did a nice job with overriding the toString method in Ship and providing a generic implementation (generic in the sense that it just returns something generic) then you also correctly overrode the toString method in each class that extends Ship. Good work. You should also be calling the toString method in your for loop though. For example:

for (int i=0; i < types.length; i++)
{
System.out.println("Ship " + (i + 1) + ": ");
//Need something here to call the toString method
System.out.println(types[i].toString());
}
BestJewSinceJC 700 Posting Maven

booster1 and booster2 are Objects, you can't print them out as if they are Strings. Use booster1.name and booster2.name or whatever your instance variables are that are Strings that will print nicely. OR override the Object class's toString() method, provide your own implementation, then call booster.toString() in the println.

BestJewSinceJC 700 Posting Maven

Your method isn't recursive. A recursive method has to call itself. Although recursive method calls usually amount to loops anyway. Not going to get into that here though. Anyway...

What does the second one do? Just show us the output. My first guess would be it didn't work because you have to look at your Unicode table. If 'f' is lower than 'Z' on the Unicode table then start will be set to 'A'. You have a problem with that I'm pretty sure.

BestJewSinceJC 700 Posting Maven

If you want to be able to programmatically find the heading, you first have to define what separates the heading from the other text. It is all just text in a JTextPane, right?

BestJewSinceJC 700 Posting Maven

For what it's worth I agree with Masijade (about learning to code GUIs by hand first, then moving on to builders if you want to). Doing so was very helpful to me and it made it a lot easier to use the GUI builder as well. If you jump into the GUI builder without knowing a lot of things first, you will end up confused and unable to modify key sections of the GUI builder's code to get it to do what you want.

BestJewSinceJC 700 Posting Maven

read the rules, until then bye.

BestJewSinceJC 700 Posting Maven

This is going to sound stupid but did you try to open it as plain text... like in wordpad? (Or you can do so in other editors). And what is the file extension? Like .txt for example or .java

BestJewSinceJC 700 Posting Maven

Read the rules pertaining to "we only give homework help to those who show effort", then come back and post something that shows effort. And no, it does not matter whether this is homework or not. Everything posted here falls under that rule.

BestJewSinceJC 700 Posting Maven

Your program isn't going to work. In your method celciusToFarenheit, you tried to compare with "if degree == c". However, if you look at this link you will see that the JOptionPane class's showInputDialog method (the one you called, where you said degree = JOptionPane.showInputDialog...) returns a String which is an Object. Since you cannot use "==" to compare Objects for equality you need to use a method such as the equals() method to test if two Strings are equal.

Another reason why you cannot use degree = JOptionPane.showInputDialog is because no showInputDialog method exists that returns an int. Did you even run your code? I could be mistaken and be looking at the wrong doc or something... but I'm pretty sure if you run your code it is going to give you a compiler error for what I just mentioned, and even if you got past that, you have the logical error with trying to compare things using '==' that only works for ints (and char, etc)

BestJewSinceJC 700 Posting Maven

Your error indicates that you attempted to parse an integer at line 128 of your program (which is correct: it says Integer.parseInt(input)). However, the program was unable to parse an int, because your input did not immediately contain an integer. Which means you are reading in the file incorrectly. For example if you say something like Integer.parseInt("This isn't an int!"); it will throw the same exception/error.

hope that helps

BestJewSinceJC 700 Posting Maven

For specific components see here: http://java.sun.com/docs/books/tutorial/uiswing/components/index.html

(for example, if you want to use a button in your app, look there to see how, or if you want to use a table, etc)

BestJewSinceJC 700 Posting Maven

Both pieces of code say they work above the code. Which one doesn't work? The second one? And can you please fix your bracketing, I can't tell which brackets go with what. The brackets should be aligned so that the closing bracket is in the same column as the opening bracket.

BestJewSinceJC 700 Posting Maven

"I am no longer able to parse the string for input into text..."

Huh? The JTextField class has a getText method. If you call myJTextField.getText() it will return a String. "Text" and "a String" mean the same thing.. did you mean you want to parse a String into an Integer? For that you could use Integer.parseInt(yourStringHere);

BestJewSinceJC 700 Posting Maven

Where is class Phrases code? It will be easier for me to find your mistakes having all your project's code.

Did you even look at his code? The problem is obviously with the way he is reading in the text file.

@OP:

Scanner's next() method reads in input between the delimiter pattern, which by default matches whitespace. In English: when you call next(), it is searching for something that has a space before and after it. Since your text file has things in it like "ahoy there" that contain multiple words, scanner.next() would've only read in ahoy, not ahoy there. Don't you want to read in the whole line? Use scanner.nextLine().

Scanner scanner = null;
		try {
			 scanner = new Scanner(new File("pirate"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int num;
		System.out.println(num = scanner.nextInt());
		scanner.nextLine();
		for(int i=0;i<num; i++){
			System.out.println(scanner.nextLine());
			System.out.println(scanner.nextLine());
		}
BestJewSinceJC 700 Posting Maven

As for S.o.S's reply, you would expect it to infinitely loop, since you want to continuously check the file for updates. In other words it is supposed to infinitely loop so I don't see why you have an issue with that. Maybe I didn't understand the issue. Anyway, I'll give you another suggestion:

Create a File Object, storing the size of the file, and then continuously (like every 2s) create another File Object (based on the same, possibly updated file) and seeing if those File Objects have the same size. If they do have the same size, no changes were made, so do nothing and wait another couple seconds. If they do not have the same size, then seek to the location of the smaller size (this is the end of the file from before) and then read in the rest of the file and print it out. Now the "updated File Object" becomes the old file Object, so update your file size variable and update your old File Object variable, and continue the process again.

BestJewSinceJC 700 Posting Maven

You should only extend a class if you need to add functionality to the class (or modify the class's functionality so that it does something different). I doubt that you need to do either of those things for JFrame, so unless you have a compelling argument, don't extend JFrame.

Also, I'm pretty sure that AWT already has a class called Frame, so you should probably pick a different class name which is more suited to your application, or it might result in confusion. And the way in which you can "know" when your JFrame's "x" has been clicked to close it is by implementing WindowListener. So use class Frame implements WindowListener, then override all of the necessary methods.

However, you should be aware that in your particular case, what I mentioned above will work but is not necessary. Instead, you can simply use the following bit of code to cause the JFrame to be closed when it is clicked on:
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation%28int%29

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BestJewSinceJC 700 Posting Maven

I was thinking about simply adding an input box onto the JPanel Menu. That way you could type a number, select a radio button then hit submit and that same window would stay open. I couldn't figure out how to do that though. I kept getting incompatible type errors.

Post your best shot at doing this and I'll help. P.S. your code you already posted doesn't make sense; why would you say do... while(false)? That's only going to do something once, and if you want to do it once, you don't need a loop. You should be looping while the user doesn't want to quit, so something like

do{
String s = JOptionPane.someInputPaneHere();
} while (!s.equals("QUIT"));

BestJewSinceJC 700 Posting Maven

Are you trying to manually do a character by character search to match words? That is a mistake. Technically it could work but the amount of effort would be enormous and fruitless. I see that your "words" can actually be multiple words with spaces between them. My first thought is to create a regular expression for each "bad word" and then scan through your input, seeing if that bad word/pattern is in the input. If it is in the input, then you can do something such as *** it out. For learning about regular expressions, see here:

http://java.sun.com/docs/books/tutorial/essential/regex/

If you read for a few minutes you'll see that their examples give you exactly what you need and you don't even need to get your hands dirty to accomplish your task. Matching shit to SHIT or Shit or other variations of lowercase/uppercase is also just as easy.

BestJewSinceJC 700 Posting Maven

I was born in UK, but was taught mandarin. I graduated with computer science and now working as a software engineer, many clients are located around the world and quite a few in China. I have been sent there multiple times to do the client meetings and designs for new systems.
Agreed that your studying Computer Science and technical skills is what you want from it, I was taught programming/theories on my degree but I didnt really "learn" how to do it properly till I started working. All computer scientists learn how to program and having something distinctively different to everyone else provides an advantage in interviews especially a language that is difficult yet is one of the most spoken languages in the world.
Having China growing in economy, I would hate to not speak the language of the country that will do a large percentage of the worlds business.

English is still the international business language and will probably remain so for many years to come. The advantage of learning Mandarin hardly compares to the disadvantage of being overloaded with schoolwork that isn't related to your major. It'd be different if the OP has an easy course load, or is an extremely good student. But I'm assuming he/she is an average cmsc student, who therefore has a difficult course load. Anyway, back to the advantage of learning Mandarin. Almost all English speaking programmers will never have ample opportunity to speak Mandarin in a business setting. So, again, …

BestJewSinceJC 700 Posting Maven

And also make sure to read about Classes in Java and Objects in Java. int, double, float, boolean, long, short, etc can not use method invocations ( like someInt.someMethod() ) because they are not class types!!!

BestJewSinceJC 700 Posting Maven

If time has no start and no end, what was before the Big Bang?

The point of that theory is that people's concept of time is untrue, i.e., there is no such thing as a start or an end. So the theory says that your question is meaningless.

BestJewSinceJC 700 Posting Maven

Uhh no. Man is nowhere even close to teleporting an apple, let alone a planet. You're delusional. Also, I'm not a physicist, but I read that article, and they didn't teleport anything in the sense you are implying. They 'teleported' it in the sense that they were able to duplicate a property of the particle, not the particle itself. The article says that they are planning to use it in communication, not that they think it is a breakthrough in the future of teleporting Mars.

BestJewSinceJC 700 Posting Maven

You already know what those things mean. If you're talking about big oh complexity or something of that nature then state your questions more clearly.

BestJewSinceJC 700 Posting Maven

Get help from a professional, in person, with your write up. Here are some tips since I've been through similar processes myself, but I'm not a professional at this, nor are most anyone on daniweb. And if you don't get help from a professional, at least get help from someone who knows good grammar. Bad grammar will cause your write up to be thrown out immediately.

1. Don't give more examples, give better examples. Talking about word processing your work isn't impressive. Get rid of it.
2. Explain all of the extras you have listed briefly. For example, what Ecommerce software? Give a one line description.
3. Some of your statements will only hurt your chances (i.e. "I didn't find their courses too demanding or challenging") it sounds like you didn't get that much out of the course. Talk about how you utilized past courses to improve your skills, if anything. Don't mention them at all otherwise.

donaldw commented: Good advice on resume/mission statement. +1
BestJewSinceJC 700 Posting Maven

SWT was created for faster native widgets - it is faster because it uses the OS's native tools to draw the widgets, essentially. However, Swing should be plenty fast for most any purposes, and I personally prefer it. I also think Swing looks nicer.

P.S. I used SWT at my internship all summer last year and I never had any problems with disposing the objects, so I don't consider that enough reason to use one instead of the other. But again, Swing just looks better, plain and simple.

BestJewSinceJC 700 Posting Maven

So. . are you simulating this process by creating threads on your local machine? Or are you actually using multiple machines and communicating with some master-server that acts to combine the results and to spawn the processes on the other machines? My reply assumes you're simulating it, and only using your local machine. If you were using multiple machines you'd need to put your "spawned" threads software on multiple machines somehow and you'd have to set up your master thread so that it could communicate with all of the other threads (to get their results and to tell them what they need to compute). Anyway, again, this is assuming local machine setup:

http://java.sun.com/docs/books/tutorial/essential/concurrency/sync.html
You should take a look at that. To communicate you can share access to fields but that explains the issues with that. So lets say you have 5 threads that need to return their results, as an Object, to a 6th thread. The 5 threads could update an array with their results (each updating a different index) and then the 6th thread could use this array to combine the results. As far as letting the 6th thread know when it is time to combine the results, check this out:
http://java.sun.com/docs/books/tutorial/essential/concurrency/simple.html
It looks like the isAlive() method will tell you whether or not a thread is finished. P.S., in those links I pointed out to you, you'll notice that it says something about creating a lot of threads, and how instead, …

BestJewSinceJC 700 Posting Maven

On the east coast.?