BestJewSinceJC 700 Posting Maven

Then you would not need to re-prompt the user for a new String, but you would need to do anything necessary to clear your stringCensor Object (such as clearing the old 'badWord' and reprompting for a new 'badWord' and telling stringCensor about the new one).

BestJewSinceJC 700 Posting Maven

What is an OBOB? And if it is solved, mark as solved.

BestJewSinceJC 700 Posting Maven

Because q+3 is longer than the total length of your rS array. You cannot access an array at an index longer than it's largest index. This is probably because your 'max' variable isn't a good indicator of rS's length (you are using 'max' as a bound on how large q+3 can be, which makes the assumption that max is always, at most, 3 less than the size of rS - which I'm guessing it is not since you went out of bounds).

If that didn't make sense, let me rephrase: You need to make sure that your 'max' variable isn't going to allow 'q' to become large enough that q+3 is larger than the length of your array. If q+3 is, at any point, larger than the length of your array, you are going to go out of bounds. (PS keep in mind that arrays are indexed by length-1 so you should actually make sure that q+4 isn't larger than the length of your array).

BestJewSinceJC 700 Posting Maven
stringCensor theCensor = new stringCensor(); // a new stringCensor is constructed
String censored = ""; // censored is initialized to a null string
System.out.print("Enter your string: "); // user prompted to enter the string
String whatTheUserPut = input.nextLine();
theCensor.userString(whatTheUserPut);

You need to put that entire section of your code into the while loop. Otherwise none of that stuff gets reset once you continue your program, does it?

BestJewSinceJC 700 Posting Maven

Tenchi, your problem with the nextLine() not working is the same problem I recently explained to another user on Daniweb. I'll paste my response to him here since the problem you have is exactly identical.


"The reason it gives you trouble is because when the user enters an integer then hits enter, two things have just been entered - the integer and a "newline" which is \n. The method you are calling, "nextInt", only reads in the integer, which leaves the newline in the input stream. But calling nextLine() does read in newlines, which is why you had to call nextLine() before your code would work. You could have also called next(), which would also have read in the newline."

BestJewSinceJC 700 Posting Maven

You should look into a Java Beginner's tutorial. There are a bunch of useful ones listed in the sticky.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

thanks a lot for the advice...would you be as kind to upload the code needed? i'd be really thankful as the program has to be submitted tomorrow and my tutor in college is no help! thank you :)

Waste of time. Someone ban this kid.

BestJewSinceJC 700 Posting Maven

And why would you ever do that instead of generating a random number and using the + operator?

Also, don't up year old threads. Then I look at my replies and wonder why I can't remember ever saying them.

BestJewSinceJC 700 Posting Maven

For continuously doing anything you can use a while loop. Look into the Scanner class for reading in user input. Use System.out.println to provide them with a prompt where they can say whether or not they want to continue. And for insuring that values are Integers, you can look at the methods in the Integer class for that. Likewise for Doubles.

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html

BestJewSinceJC 700 Posting Maven

I didnt said that your solution is bad, but the easier for me is the cgeier solution, and it needs fewere variables to work (when number is big).
And I also said "Thanks for all help" it did included your solution, sorry for not making me clear (again).

In the future, the "down voting" feature should only be used when somebody says something rude or incorrect or both, not when they say something correct that you don't understand. In that case, you should just reply and ask them to elaborate. I'm not angry, just saying, it was frustrating to get down voted for seemingly no reason.

:)

Also, the algorithm to print out the ith digit in an integer only requires one variable of storage - the integer itself. All you need to do is divide by ten to the appropriate power, then use modulus and print it. The code I posted uses two variables, but even if the idea were extended (for an integer of arbitrary length), the number of variables needed would still be two. And while his solution might have been easier for you, you should consider any solution a learning opportunity.

Anyway, again, I'm upping a thread that's marked solved, so I digress. Lets leave it at that.

BestJewSinceJC 700 Posting Maven

You need a for loop, not an if statement. http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
You need to declare two integer variables outside of your for loop. One to keep track of the total amount of money earned, and one to keep track of the amount you need to add next time. For example, the first time around, the "amount to add" will be 1, then 3, then 9, then 27.

Inside your for loop, you need to add the current "amount to add" to your total, then update the "amount to add" variable by multiplying it by three. Good luck.

BestJewSinceJC 700 Posting Maven

Ok.

usertype = logs.getUsertype();
System.out.println(usertype);

If you do that in your actionPerformed, then you print userType from within another method, after you have clicked on your button, then you will see that usertype changed. The problem you are having is that you must have done something like this:

button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              Login logs = new Login(user.getText(), pass.getText());
              //this one is querying the database and getting an int value for user type. 
                usertype = logs.getUsertype();
            }
        });
//some more codes to add to frame and stuff

System.out.println(usertype); //WILL ALWAYS PRINT 0

}

usertype (in the println that I commented next to) will always print 0 because it is in the constructor. You added an action listener to the button, but you didn't click the button yet. So after the code I posted above adds the action listener, it immediately goes and prints "usertype" - but you haven't clicked the button yet, and therefore usertype has not been changed yet, so it prints 0!

Basically, I don't think you don't have a problem, you just think you have a problem. If you *really* want to verify that "usertype" is being set correctly, just do a System.out.println(getUsertype()); inside of the actionPerformed method at some point after you set the usertype.

BestJewSinceJC 700 Posting Maven

No guarantees, but I read through this thread and it might shed some light. Of course, it is a C++ thread, but it is on the same exact topic (the OP there also claims the clock is always returning 0). One of the suggestions there is to try to increase the amount of work you're doing and then see what clock outputs. That baffles me a little, since it seems like you are doing a good deal though. Nevertheless, http://www.daniweb.com/forums/thread120862.html

BestJewSinceJC 700 Posting Maven

This is not a snippet. It is a request for help. And when you are asking for help, it is probably not a good idea to post a snippet. And read the rules stickied at the top of the forum, nobody is going to write your code for you, we're here for guidance.

BestJewSinceJC 700 Posting Maven

Oh, and another thought: You know you've been on daniweb for too long when you're looking for new threads you haven't replied to yet and there aren't any left. :(

BestJewSinceJC 700 Posting Maven

Well. . I'm in the U.S., I've had one internship, haven't graduated yet, and accepted 73k starting for when I graduate . . so I guess it depends on how much a Masters degree is worth. But also keep in mind that benefits can mean a whole lot. So if you're making 80,000 but have much better benefits than someone making slightly more, you might be better off. Also, keep interviewing. Interviewing can't hurt since it is a valuable skill, and if you get more offers, you can pick and choose which you think is the best.

BestJewSinceJC 700 Posting Maven

>>Si. Es muy delicioso. Quiero ir a Nicaragua degustar la comida.
So Spanish and japanese are very good, I agree. But I don't know about Nicaraguan food and why you want to go there to taste it:-O
Looks very Spanish to me. Why not go for Belgian cuisine instead?:D

I'm a little late replying, but. . it is cheap and supposedly delicious. And Nicaragua is part of Latin America. When I said "Spanish food" that is what I meant, I didn't mean Spain necessarily.

BestJewSinceJC 700 Posting Maven

I hear the terms used interchangeably, they have no difference in meaning to me except that geek seems a little stronger since nerd is used more often. A nerd could also be anyone I suppose, whereas a geek is typically someone whose hobbies & life 100% revolves around geeky/nerdy activities. But again, I'm sure someone else will tell me that the definition is the opposite...

BestJewSinceJC 700 Posting Maven

In addition to what Peter said, you might find some of the responses here helpful: http://www.daniweb.com/forums/thread232056.html

BestJewSinceJC 700 Posting Maven

Hmm... try defining that 'ActionListener' outside the constructor.

Wrong. Run my code if you don't believe me.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class RandomTest extends JPanel implements WindowListener{
	
	int random = 0;
	public RandomTest(){
		JButton button = new JButton("Click me");
		
		button.addActionListener(new ActionListener(){
		
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				random = 5;
				System.out.println("Variable random is " + random);
			}
		});
		this.add(button);
	}
	
	public static void main(String[] args){
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		RandomTest test = new RandomTest();
		frame.add(test);
		frame.addWindowListener(test);
		frame.setSize(300,300);
		frame.setVisible(true);
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("Window is closing. Variable random  = " + random);
	}

	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	
}
BestJewSinceJC 700 Posting Maven

To be honest, I'm not quite sure what you're asking, but it sounds a bit out of my league. The only reason JTable itself knows to even *put* the JCheckBoxes into your JTable is because it uses getValueAt(row,column).getClass() to see what class it is from. From the code you posted, you already know where the event is happening. If you want to know what type it is, you could use instanceof, I suppose. But I'm sure you know about that so I'm probably not being very helpful.

PS: You might want to rephrase your question, because there are a lot of people that regularly post in the Java forum who are much better with Swing than I am, so the fact that they haven't responded might indicate that they didn't understand your question either.

BestJewSinceJC 700 Posting Maven

It *should*. Although I have personally occasionally had slight GUI issues when trying to run the same jar on Mac & Windows. But yes, the idea is that it will do so. If I were you, I'd test it on multiple platforms to be sure.

BestJewSinceJC 700 Posting Maven

You'll have to post the binarySearch method, since it is returning the -7 and all the other values (at least it seems that way). Also, thank you for posting in code tags. It is much appreciated.

BestJewSinceJC 700 Posting Maven

you will have to write a program that reads a 4-digit positive integer from the user and prints out the following information on the screen:

Re-read your project assignment. Pay particular attention to the part that I bolded.

BestJewSinceJC 700 Posting Maven

Just modulus (%) by ten. That will give you the last digit.

My response was perfectly valid. I don't see why it was down voted, but to elaborate:

public static void main(String[] args) {
		// TODO Auto-generated method stub
		int myInt = 123;
		int newInt = myInt%10;
		System.out.println(newInt);
		newInt = myInt/=10;
		System.out.println(newInt%10);
	}

That concept can be extended as far as you want, i.e., you can get whatever digit you need by doing that X number of times.


edit: Also, sorry guys for upping this when it was marked solved, but it was frustrating to get down voted (with no explanation) when I was only trying to help.

BestJewSinceJC 700 Posting Maven

No, as I tried to explain, your problem is that you don't know how to start a new thread rather than interrupting someone else's. To help you out: http://tinyurl.com/yzgjk68 . Go do that and click on the first link. Read carefully.

BestJewSinceJC 700 Posting Maven

You must have missed the forum rules and the 'create new thread' button at the top of the forum. Shame.

BestJewSinceJC 700 Posting Maven

What - that you can't post in code tags?

BestJewSinceJC 700 Posting Maven

Is there a method I can invoke that will tell me who the caller was?

You basically already did. Object source = event.getSource() returns the Object that caused the event to be fired. So you could just use '==' to determine which Object it was at that point, if you need to.

BestJewSinceJC 700 Posting Maven

Well if the number of elements in the array is odd, it is logically the number directly in the center. Otherwise, it is the two numbers in the center added together and divided by two.

BestJewSinceJC 700 Posting Maven

post in code tags and post all of your code.

BestJewSinceJC 700 Posting Maven
Character ch = new Character('\u00C3');
char prim = ch.charValue();
System.out.println(prim);

Something I just learned how to do after a quick look up in the Character class documentation. I'm sure if you read some stuff yourself and try some things out, you'll find many more useful methods. http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html

peter_budo commented: Good pointer +11
BestJewSinceJC 700 Posting Maven

It's because the compiler doesn't think that your method is guaranteed to return either true or false. I.e., it thinks that it's possible to reach the end of your method without returning anything at all. If you're positive that your method will always return either true or false (based on your if statements), then you can go ahead and just put "return true;" at the very bottom of the method and the error will go away. I'd also put "throw new Exception("Shouldn't have gotten this far")" or something similar while you debug.

To drive my point home, consider this code:

public static boolean maybeReturns(int i){

if (i > 100) return true; 

}

The compiler would give the same error since it doesn't think that my method will *always* return something. Your case (in the eyes of the compiler) is the same, except that you code is a lot more complex.

BestJewSinceJC 700 Posting Maven

Isn't Vector a generic class? You would have to define the generic type when you create the new vector.
Judging by your code you would want something like:

Vector<DoctorData> dataList = new Vector<DoctorData();

Does that fix the problem? ...I'm pretty sure vector is generic...

Yeah, it is. That's the error I expected to see, but you never can be too sure without seeing the code.

@OP, you might want to take a look at this.

http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html

BestJewSinceJC 700 Posting Maven

Just modulus (%) by ten. That will give you the last digit.

BestJewSinceJC 700 Posting Maven

I read occasionally. Authors I like include: David Baldacci, John Grisham, Brian Jacques, J.K. Rowling.

BestJewSinceJC 700 Posting Maven

Post the segment of your code where you get your warning and any other relevant portion of your code. In code tags.

BestJewSinceJC 700 Posting Maven

Seriously? I mean I'm pretty bad at algorithm analysis, I'm not going to lie. . but read some stuff: http://en.wikipedia.org/wiki/Quadratic_function

I'm assuming you know what "linear" means. There really isn't a way to answer your question without just giving you the answer, so that's where I'll leave it.

BestJewSinceJC 700 Posting Maven

The reason it gives you trouble is because when the user enters an integer then hits enter, two things have just been entered - the integer and a "newline" which is \n. The method you are calling, "nextInt", only reads in the integer, which leaves the newline in the input stream. But calling nextLine() does read in newlines, which is why you had to call nextLine() before your code would work. You could have also called next(), which would also have read in the newline.

javaAddict commented: Smart explanation. Couldn't find it. +4
BestJewSinceJC 700 Posting Maven

In actionPerformed, you create a new "Login", not a new "Log". Why didn't you post your Login class? (Post it :) )

PS: It seems to me from the way that you created a new "Login" and then called a method identical to one I see in the Log class, that Login extends Log, and that in the Login class, you did not override the getUserType method. But that's just a guess. I'm pretty sick right now, but post your class and someone will take a look at it.

BestJewSinceJC 700 Posting Maven

I already provided an answer in the thread you made in the Java forum. But logically n! < n^n and log(n^n) = n log n.

BestJewSinceJC 700 Posting Maven

If you're done like you say, then post all of your code including the main so that I can run it. I'll see if I can fix it which I probably can, but generics are a little rusty in my mind right now and I see nothing right away.

BestJewSinceJC 700 Posting Maven

I'll give you some hints and leave the rest of the work (such as using the definition of theta to come up with the values that prove it's big theta) up to you. But these are just my thoughts, no guarantee that it's correct so listen at your own risk.

Consider that n! = n (n-1)(n-2). . . 1. Now consider that n!, therefore, is < n^n, which can be shown simply by aligning each term in n! and each term in n^n.

Now use the logarithmic property: loga(x^r) = r loga(x)

Then use your theta values after finding them to wrap it up. In fact (if it is true and theta values can be found) you don't even need any other logic, unless it was requested by your instructor.

BestJewSinceJC 700 Posting Maven

Yes, I bet the frendly people who help here would wish more people would search for answers before posting duplicate questions. :)

On a side note, I'm going to have to ask for help in a second, since I have a switch statement that just isn't working correctly. :(:(

Agreed. It's even more painful when someone asks "how do you do X" when "how to do X" was just answered in that same thread.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

Would I need to check each individual character of the equation against each possible operator? (+, -, *, /, etc.) or is there a much simpler way?

Yes, you'd need to compare against each operator. Java uses Unicode, not ASCII, but even if you used the Unicode values, you'd be doing the same thing as comparing against each operator (unless the operators are right next to each other in the Unicode table, in which case, you could say something like "if (charImComparing >=120 && charImComparing <= 125)".

BestJewSinceJC 700 Posting Maven

Cool, glad you got it to work. If there's anything you still have trouble with let me know and I'll help you out later today. I'm going to do a really fun Iphone program so I'll probably be off until then though.

Oh, and mark as solved if you don't have any more ?s

BestJewSinceJC 700 Posting Maven

Because phrase is a String object, and the "equals" method for the String class is implemented so that it compares two Strings to see if they are the same. If you are interested, you should read about the following topics:

Method overriding
Inheritance

And also, mark solved threads as solved

BestJewSinceJC 700 Posting Maven

Whether or not the stack is empty for an invalid equation depends on your implementation. However, if in your implementation you "pop" an element off of the stack and then compare it to the next '}' or']' or ')', your stack would be empty even if there was an invalid condition.

(Ex: {) ):

Stack after seeing { = {
See ')' and pop top of stack. Top of stack, '{', is not the correct element for ')'. Therefore your stack is empty because you just popped the only element on it, but you have an error condition.

I'm not saying you don't have an error in your stack class, but you can easily come up with an error when your stack is empty if you are popping the elements off the stack before comparing them. If you post all of your classes again (w/ whatever your most up to date code is) I'll look at them later and help you figure out what's wrong.