BestJewSinceJC 700 Posting Maven

Ok and? I think it's pretty obvious how java and mySQL can work together to put together a generic idea like a "project management system" that doesn't even have any specific guidelines.

BestJewSinceJC 700 Posting Maven

It makes sense that private variables wouldn't show up in a javadoc because only the class itself has access to private variables. So it is just not necessary.

BestJewSinceJC 700 Posting Maven

So which part are you confused about? Reading in the values? Calculating the formulas? The formulas are standard formulas, so if you don't get them, just look up those terms on google and you'll find plenty of explanations. Your professor didn't make those up. And to read in the values, you can make a Scanner. Test each value read in; if it is -1, stop reading in values, and do not include the -1 value in your calculations. So you'll basically be using a while loop to read in all the values, then adding them to an ArrayList<Integer>.

BestJewSinceJC 700 Posting Maven

Then do System.out.println("f") afterwards. lol.

BestJewSinceJC 700 Posting Maven

You're probably storing it in a double variable. For example

double result = 0.0;

result = average(x,y);
Now result is a double which is a larger type than float.

BestJewSinceJC 700 Posting Maven

You can't use == (or !=) to test for equality against Objects. You have to use the .equals() method. And your method is intended to return true if you successfully added the event to the calendar and false if adding the event to the calendar was not successful. Presumably, an event would be added successfully so long as the year, day, month, etc were all valid and provided the event itself was not already in the calendar. Otherwise, it would not be added successfully, and you would need to return false. Also - you made no attempt to actually add the event to the calendar, which is what you should be doing in that addEvent method. Before adding the event to the calendar, you need to check all those things I just mentioned. (Like checking that the year, day, month are valid).

BestJewSinceJC 700 Posting Maven
return (float)((x+y)/2.0);

OR

return ((float)(x+y))/2.0;
BestJewSinceJC 700 Posting Maven
while(wordQuit == 2);

What is that for? ^
And what is your correctGuesses variable for? You never used it.

And the reason you got InputMismatchException is because your scanner tried to read in one type of (String, int, double, etc) but your input did not have that type immediately in it. See here

BestJewSinceJC 700 Posting Maven

Actually, at the risk of sounding whiny, I retract my statement. But I still believe that new members misuse the down vote system to "spite vote"

BestJewSinceJC 700 Posting Maven

Like the docs say, split does not return the character that was split around. My point in my previous post was that you can easily figure out where the characters were anyway by using a little intuition.

BestJewSinceJC 700 Posting Maven

You need to register an ActionListener with the buttons as they are created, similarly to how you declared the ItemListener (with b.addItemListener). You can find examples of ActionListeners being used online, here is one similar to the ItemListener you used. http://www.javaprogrammingforums.com/java-tips-tutorials/278-how-add-actionlistener-jbutton-java-swing.html

In your actionPerformed method, you'd just use JFrame's remove() method on the button. So you'd use me.remove((JButton)event.getSource()) where event is the argument to the actionPerformed method.

BestJewSinceJC 700 Posting Maven

Are we supposed to read your mind? What do you need help doing?

BestJewSinceJC 700 Posting Maven

Yes, it would work - you are correct. See here for definitions of predecessor and successor.

BestJewSinceJC 700 Posting Maven

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

You need to mark solved threads as solved - not to do so (and not even a thank you post)? is rude.

collections.sot(values);

There is no sot method. Or collections class. It's Collections.sort(values). . the case is important. And you should only call Collections.sort() after you add all the values from both files to the array. You are sorting after you add the values from one file, which does nothing useful. Then, after you sort, you should print the values out to a file.

edit: And there is no need for the extra array "temp" or anything like that. You should just create an instance of some class that allows you to write out to a file. You should then use that Object to write each element in your array out to a file using a for loop. There are a lot of examples online of writing to a file. . I suggest PrintWriter, as I think I did in the other thread I helped you in.

BestJewSinceJC 700 Posting Maven

no problem. If you want to go that route, I don't see how he could be upset. There are a lot of tutorials online on how to use structs.

BestJewSinceJC 700 Posting Maven

True enough, vega. I buy small hard drive sizes and I have a 1TB external and neither are ever anywhere close to full.

BestJewSinceJC 700 Posting Maven
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ComboBoxFrame extends JFrame {
	/***/ private static final long serialVersionUID = 1L;
	
	private JComboBox b;
	private String s;
	private int x = 0;
	private JButton g[] = new JButton[10];
	private ComboBoxFrame me;
	private String courses[] = 
		{ "Advanced Functions", "Calculus",  "Chemistry", "Physics" };

	public ComboBoxFrame() {
		super("Pick your courses!");
		setLayout(new GridLayout(3, 3));
		me = this;
		b = new JComboBox(courses);

		b.addItemListener( new ItemListener() {
			public void itemStateChanged(ItemEvent event) {
				if(event.getStateChange() == ItemEvent.SELECTED) {
					s = (String) b.getSelectedItem();
					System.out.println(s);
					g[x] = new JButton(s);
					add(g[x]);
					me.validate();
					//g[x].addActionListener(this);
					x++; 
				} } } );
				
		add(b);
	}
	
/**	public void actionPerformed(ActionEvent e) {
		String s;
		for(int x = 0; x < 10; x++) {
			s = courses[x];
			if(e.getSource() == s) remove(g[x]);
		}
	}*/
	
	public static void main(String args[]) { 
		ComboBoxFrame comboBoxFrame = new ComboBoxFrame();
		comboBoxFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	    comboBoxFrame.setSize( 350, 150 );
	    comboBoxFrame.setVisible( true );
	}
}

Now try.

BestJewSinceJC 700 Posting Maven

To make it easier on yourself, you should have two Strings. One String should contain the correct word. The other String should contain what you are displaying to the user. If you do this, when the user guesses a letter, you can say

if (string.contains("A"){
// In here use the String class's replaceAll(oldChar, newChar) method.
}else{
//guess invalid, do other stuff
}

If you don't know what the replaceAll(oldchar, newChar) method is or how it is used, check http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

BestJewSinceJC 700 Posting Maven

Please don't PM daniweb members. Personally I don't mind, but in general, that is the rule here. If people want to help they will respond in your thread. Regarding your PM, if your professor mentioned that it was extra credit to use more than a 2D array, then I must be mistaken about my entire post, so ignore all my posts in this thread. Thanks.

BestJewSinceJC 700 Posting Maven

My advice was to not use a 4 dimensional array when one is not needed. In fact my claim is that using a 4d array in this case is not good programming. If you were to declare a 2d array with this data:

seats where MAX SEATS is 50
people where MAX PEOPLE is 10

You would then have array[10][50] which is 10 arrays of 50 elements each = 500 elements. But you only have 60 elements. It seems to me that the larger your MAX sizes are declared, the more space you are wasting, unless I am either that tired, or your algorithm is that strange. Additionally, using a 4D array is obviously making your program difficult to debug, so why don't you switch to a sensible alternative? If you don't believe me, then wait for the C experts to come in here, they'll be quick to point out (rightfully so) that I'm wrong if I am wrong.

BestJewSinceJC 700 Posting Maven

That is actually good logic - but it assumes that the MouseListener wouldn't get re-added due to the method calls being blocked/having to wait for receive, so it probably runs into the same problem as the variable does. Although I'm not sure and honestly don't feel like investigating. But I'm glad you have it working now, wish I could've been of better assistance.

PS mark solved

:)

BestJewSinceJC 700 Posting Maven

Because Strings are immutable, so every time you say string+= in the background, another String is being created and all of the contents are copied into memory. This process takes a lot of time once the String gets large. Use the StringBuilder class instead.

P.S. I made that mistake on a graded project in the past - very embarrassing when my program ran quickly and properly on small to medium sized input files but then when a long novel such as, I don't know, the Iliad is supplied, my project didn't finish fast enough for the TA to care (within 30 seconds as I later learned). But it sure taught me to pay more attention to little details and also to test for more input conditions before assuming I was finished!

BestJewSinceJC 700 Posting Maven

Let me get this straight before I dive into trying to help you. So you are displaying the String as "_ _ _ _" initially, where every second character is a space? Then once the user guesses a correct letter, you replace the String with it? (So like "_ _ A _" after they correctly guess A)? If you aren't doing it like that then how are you saving the correct String? And how are you saving the String that you display to the user?

BestJewSinceJC 700 Posting Maven

I must say i agree. I will do the same in the python forum.. If vegaseat is already there, i needn't bother.

I don't, and I occasionally double post with someone else or vice versa. Serves me right.

:(

BestJewSinceJC 700 Posting Maven

Daniweb usually seems pretty fast to me. Well, fast enough, anyway. But I did get the same message the other day. . not complaining, I've been on forums that get them much more frequently.

BestJewSinceJC 700 Posting Maven

"It requires a very unusual mind to undertake the analysis of the obvious"

-Alfred North Whitehead

BestJewSinceJC 700 Posting Maven

If by convert, you mean rewriting the code so that the original intention of the program is still there, then yes, you can do it. Usually. If it is just a text input/output program as opposed to a GUI program then you should be able to rewrite the program in Python without too much trouble.

BestJewSinceJC 700 Posting Maven

That drunk guy video is unbelievable. I've been around my fair share of drunks, but nothing remotely close to that. It looks like a supernatural power is controlling him with a will to get beer.

BestJewSinceJC 700 Posting Maven

Ok, I used the site Ancient Dragon provided and I got more reasonable results.

BestJewSinceJC 700 Posting Maven

12705 kbps download almost the same upload

wtf

BestJewSinceJC 700 Posting Maven

Well, thank god that somebody else stepped up, because I was getting quite frustrated and it isn't even my program. Haha. Although after a quick look I don't see why your version is any different than mine was, but I suppose it is those two while loops that truly make the difference. But no need to explain unless the OP is curious - I'll take a look at it when I get up the effort to look at this thing without getting frustrated again.

BestJewSinceJC 700 Posting Maven

Hi,

Ive read that document through 3 times and the examples are good. But i have a couple of questions.

When would you choose to use it?
Can you give me an example of when you have used it?

i dont want code, i just need to understand how i can use it for something useful...

I've used it in projects to send "Objects" (as data) across Sockets and reuse the Objects on the other side. You could send the Objects as data and have both client and server know the exact format of the data to recreate it, but serializing it is much easier. You can also use it to store data in text files. The use of storing it in text files would largely be the same: it would be much easier to store and retrieve the data than if you wrote your own format style for the text file then read it in using knowledge of that format style.

kvprajapati commented: Great! +6
BestJewSinceJC 700 Posting Maven

why would you post 'php code error' in the java forum?

BestJewSinceJC 700 Posting Maven

Don't post questions in code snippets. Go read daniweb's rules. Specifically about which forums are appropriate to post in, what kind of questions are appropriate, and how to post a thread.

BestJewSinceJC 700 Posting Maven

You should switch to using a struct to represent your ticket class, destination, seat, and time. . All four of those things are obviously related data. You're only going to cause yourself headache trying to use a 4d array for this purpose, and using a 4d array like that doesn't make sense for your data . Why not create a struct to group the related data and then create an array of structs?

BestJewSinceJC 700 Posting Maven

If you want a less elegant solution, then simply call String.split() two times on your String. The first time split on R, and the next time split() on K. You already know where your R and K are because they are at the index of the original string where the array was split around. So if you wanted to print out a list of where R was, do something like

String[] wheresR = myString.split(splitOnR);
int index = 0;
for (String str: wheresR){
index+=str.length();
System.out.println(index);
}

Then I suppose you could have the letter at the beginning or at the end of the String and you wouldn't be sure, but you can check for that as well by using charAt.

BestJewSinceJC 700 Posting Maven

Time it takes my Linux box to load on startup:
~45 seconds to one minute (and it has issues)

Are we comparing things that depend on your hardware's speed now? In that case my dell running on Vista loads in less than that. I'll be back online shortly, I'm actually going to time how long it takes me to open Firefox and start using it.


Edit:

It took me < 20 seconds to open Firefox and go to daniweb's home page after shutting off my computer and restarting Vista. I started the timer when I clicked the login button.

BestJewSinceJC 700 Posting Maven

I'm pretty sure you can Serialize any object that implements the Serializable interface. You can serialize the entire library object if you want, which would of course serialize every other object inside it automatically. Read the link I gave you.

BestJewSinceJC 700 Posting Maven

My example was pretty long, but try to grasp the concept and I think you'll be able to complete your program. Again, the basic idea I'm proposing is that you multi-thread your application so that the read() method doesn't block the main thread. I'm not sure of the best way to do this, but I'd first try to create a new Thread in which you'd run the receive() method. Hypothetically, you could also make sure that any time the mouse listener method was called it happened in a different thread, but I don't know how you'd do that (since it depends on an event). So if it was my program I'd try the first option. Anyway I really hope this works out for you. I'm no expert in Socket programming or in multithreaded programming, and everything I said here could be completely wrong. But I know the basic concepts of each, so hopefully that little knowledge will be helpful to you here. Good luck

:)

BestJewSinceJC 700 Posting Maven

Sorry, took too long and couldn't edit my last post. Update:

Ok, so this seems to be the issue: since read() blocks while it waits for input, when the client's receive() method is executed, all subsequent mouse clicks on the client "don't happen" until after the client finishes receiving the data via the read() method. So when you click out of order, you are putting an extra event on the thread which doesn't get executed until after read() is done. What you really want to do is "throw away" the click and pretend it didn't happen at all. But I think you need to multi-thread your application. Hopefully someone else on Daniweb will verify this so that I'm not unintentionally leading you astray, but as of now, I believe this to be accurate.

This code will demonstrate to you what I'm talking about. If you look at the ClientTurn_flag variable, you'd expect that once you click (which calls receive() and sets ClientTurn_flag to false), the next time you clicked on the client's window, it should print out "wasn't client's turn". However, it doesn't do that, since the read() method is blocking the thread. In fact what *I think* happens is this. Lets say you run the program, then click:

1) Click client's window
-At this point ClientTurn_flag is true.
-client sends it's coordinates to the server.
-client calls receive method and waits for the server to take it's turn. The receive method calls read(), …

BestJewSinceJC 700 Posting Maven

The error either has to do with memory consistency, or the fact that the InputStream class's read() method blocks while it waits for input (and the read() method gets called multiple times when you keep clicking on the Server's window when it is the client's turn). I'll figure it out soon enough. But if I don't, I think you should read about these avenues as well.

Update:

Ok, so this seems to be the issue: since read() blocks while it waits for input, when the client's receive() method is executed, all subsequent mouse clicks on the client "don't happen" until after the client finishes receiving the data via the read() method. So when you click out of order, you are putting an extra event on the thread which doesn't get executed until after read() is done. What you really want to do is "throw away" the click and pretend it didn't happen at all. But I think you need to multi-thread your application. Hopefully someone else on Daniweb will verify this so that I'm not unintentionally leading you astray, but as of now, I believe this to be accurate.

BestJewSinceJC 700 Posting Maven

Actually you are correct, I did not test my modifications thoroughly enough. The problem seems to reside in the server class though, not the client class. I'll take a look again.

BestJewSinceJC 700 Posting Maven

I have two family members that bought Acer computers at around the same time. This was less than two years ago; neither computer is being used anymore - they both had to buy new laptops because of crappy parts. Basically the screen completely separated on my dads and I don't know about my sister but she has an HP now. Acer = bad

BestJewSinceJC 700 Posting Maven

Haha. That's pretty funny and extremely nerdy of them.

BestJewSinceJC 700 Posting Maven

Code a ILoveYou class , which will display love symbol is various color combination .

System.out.println("love symbol is various color combination .");

Done.

BestJewSinceJC 700 Posting Maven

^ Your program won't work without any String operations, unless your String is guaranteed to not have any spaces and the case is guaranteed to be the same throughout. You could potentially ignore spaces and convert the case on the fly, but then why not just do it to begin with? Didn't you listen to anything I said? Anyway, I'll trade you a program for a program:

I need a complete Java program that will translate any English sentence I enter into perfect Spanish. Once you give me this I'll write your program for you. Thanks.

P.S. This isn't your thread, if you had a legitimate question instead of that request for people to do your homework, I would have explained with far less sarcasm. But nobody cares, stop jacking threads.

BestJewSinceJC 700 Posting Maven

Haha. No details? If you want to impress someone you'll have to program something that is either extremely cool (which would involve coming up with your own idea) or program something that is above your skill level. I'd program something that isn't that difficult such as the client/server game that was recently posted here, but that is probably above your current skill level by a little bit. In addition, such a game demonstrates at least basic knowledge of important concepts. i.e. the idea is to implement some simple game using sockets. Obviously it'd be an interactive game where client and server are involved in some type of communication. For example, the client drags their mouse around on their JFrame window, and have the server draw circles (or some other shape) at whatever position the server is currently dragging.

BestJewSinceJC 700 Posting Maven

A golfer hooked his tee shot over a hill and onto the next fairway. Walking toward his ball, he saw a man lying on the ground, groaning with pain.
"I'm an attorney," the wincing man said, "and this is going to cost you $5000."

"I'm sorry, I'm really sorry," the concerned golfer replied. "But I did yell 'fore'."

"I'll take it," the attorney said.

..............

"A group of dinner guests were blaming all of America’s troubles on lawyers when a woman said, “They aren’t all so bad. Why, last year a lawyer gave me $1000.”
“I don’t believe it,” the host responded.

“It’s true, I swear it,” said the woman. “I had a complicated personal injury case and what with the lawyer’s fee, the cost of expert witnesses, the expense of the appeal and so on, my bill was $41,000. When the judgment only amounted to $40,000, my lawyer simply forgave the difference.”

BestJewSinceJC 700 Posting Maven

I read most but not all of this thread, apologize if any of these are repeats but I don't think they are:

"A doctor and a lawyer were attending a cocktail party when the doctor was approached by a man who asked advice on how to handle his ulcer.

The doctor mumbled some medical advice, then turned to the lawyer and asked, "How do you handle the situation when you are asked for advice during a social function?"
"Just send a bill for such advice" replied the lawyer.

On the next morning the doctor arrived at his surgery and issued the ulcer-stricken man a $50 bill. That afternoon he received a $100 bill from the lawyer. "


/....

"An old man was on his death bed. He wanted badly to take some of his money with him. He called his priest, his doctor and his lawyer to his bedside. "Here's $30,000 cash to be held by each of you. I trust you to put this in my coffin when I die so I can take all my money with me."

At the funeral, each man put an envelope in the coffin. Riding away in a limousine, the priest suddenly broke into tears and confessed, "I had only put $20,000 into the envelope because I needed $10,000 for a new baptistery."

"Well, since we're confiding in each other," said the doctor, "I only put $10,000 in the envelope because we needed …

BestJewSinceJC 700 Posting Maven

I found the problem. Your code is way more complex than it needs to be. Essentially all you *need* in the client is the "clientTurnFlag", the send method, and the receive method. Initially in your main method you don't do anything except for opening the client's window and setting it visible. Your problem was basically setting the flags to false at the incorrect times. Here is your (much updated) code. I removed a lot of unnecessary code. There are logically only a few places where you should be setting your flags to true and false. Btw, you only need to accept the socket once - you shouldn't be accepting the same connection over and over again on your ServerSocket.

package game;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;

import javax.swing.*;

public class Clientms2 extends JFrame implements MouseListener
{
	private static final long serialVersionUID = 1L;
	
	JFrame container;
	static InetAddress address;
	static Socket s;
	static String host = "localhost";
	static BufferedOutputStream bos;
	static OutputStreamWriter osw;
	static BufferedInputStream bis;
	static InputStreamReader isr;
	static int port = 5656;
	static String message;
	static boolean ClientTurn_flag = true;
	//static MouseListener l;
	
	static int tempx, tempy;
	static int mouseX, mouseY;
	static StringBuffer x, y;
	
	public Clientms2()
	{
		super("Client 1: Player 1");
		setSize(400, 400);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setResizable(false);
		addMouseListener(this);
		try {
			address = InetAddress.getByName(host);
			s = new Socket(address, port);
		} catch(Exception e){System.out.println("You fail at socket programs sucka!!!");}
	}
		
	public static void main(String args[])
	{
		Clientms2 client = new Clientms2();
		client.setVisible(true);
		
		
	}

	@Override
	public void mouseClicked(MouseEvent e) 
	{ …