BestJewSinceJC 700 Posting Maven

Should we assume that you followed the rules, asked a specific question, and showed effort towards solving the problem? Or would you like the working code, freshly baked, straight from [Salem, Ancient Dragon, WaltP, Narue]'s oven? In the latter case you're more likely to get my stale humor instead.

:icon_rolleyes:

romariejhoanna commented: He/She did not help at all.... +0
BestJewSinceJC 700 Posting Maven

The funniest thing about Ancient Dragon's post is that the google search's second result is this thread.

:)

BestJewSinceJC 700 Posting Maven

But her profile says "Code Goddess"! And Dani is the most powerful on Daniweb . . the God of Daniweb. I'm convinced.

BestJewSinceJC 700 Posting Maven

I think that the way Dani has chosen to do the rep system is good. The fact that some members seem to have gotten the short end of the stick isn't the whole story: if Dani changes the rep system in certain ways, then the only thing that will change is that different members will see it as unfair. For example, if Dani changes the formula so that Ryshad's rep power becomes closer to the other member with 11K posts, the member with 11K posts might see this as unfair (i.e. their posts are no longer worth as much). Similarly, if she changes (for example) the system so that you gain another rep point every six months, then certain members will have enormous rep. Therein lies the problem. What Dani came up with might not be the only good solution, or even the best solution, but it is reasonable.

Edit:

My only suggestion is that perhaps sponsorship should give someone added rep power points, as should being chosen as member of the month (btw, how do we view a list of past 'members of the month'?). Being a sponsor is, in my opinion, a kind thing to do and shows appreciation for the site, so it couldn't hurt to give those people an added rep point for it (and I don't think it'd hurt from a business standpoint either). And being chosen for member of the month means you've done something right.

BestJewSinceJC 700 Posting Maven

the code i provided works, but only if you run it through command line.
you had excess lines that stopped the code from working, in addition, when you get input through command line, they are initially in the form of string. to manipulate them, you need to convert them in numbers, which is what i did and explained where i did so. I hope you can make any use out of the code!

Remember what you just did and never do it again, then you'll be closer to helping people learn. Giving people the "working" code doesn't help them learn. It encourages them to disregard rules, both written and understood, and to have others do work for them instead of learning on their own, which can best be accomplished through trying, failing, and repeating.

I am sorry! Dont take it personally

I don't hold a grudge. As long as you keep the things I mentioned before in mind when posting questions from now on, and as long as you don't tell me I'm bad at doing my job, I'm more than willing to help you.

:)

Salem commented: Well said, WELL SAID!!!!! +19
BestJewSinceJC 700 Posting Maven

This is how I think it works. Like I said before I've never used it. This is simply from reading the Javadocs I looked up on google.

public class RPG{
double variable1;
String variable2;

public static void main(String[] args){ 
RPG myGame = new RPG();
Class myClass = RPG.getClass();
Field myField = myClass.getDeclaredField(variable2);
myField.set(myGame, new Double(10.9));
}

}

And one last time I will warn you against this: I'm almost finished my cmsc degree and I've never encountered a reason to use something like that in Java. None of my teachers have even mentioned it. Maybe some other posters who have worked in industry will disagree, but I see it as a tool that is made available for important, but rare uses. Since you already know what all of your possible variable names are (they are defined in advance, Java is a strongly typed language!) you can just use if statements which are far more clear and almost certainly more efficient.

Olliepop commented: Thanks a lot for all your help! +1
BestJewSinceJC 700 Posting Maven

Or this

double val = .2;
val += .1;
System.out.printf("%.2f", val);
BestJewSinceJC 700 Posting Maven

A more feasible way to decide which array to store it in would simply be to use if statements to decide. So

if (myString.equals("arrayName")){
arrayName[someIndex] = someData;
}

Other than that, you could look at the Java Class called "Class" and use some of those methods. Take a look in the "Object" class, it has a method called "getClass" that returns a Class Object. This method might be helpful. I'll warn you though that I don't personally mess around with "Class" so I can't guarantee results. But I recommend avoiding its use if at all possible.

BestJewSinceJC 700 Posting Maven

"Rumour" is spelled rumor in the U.S. :p

BestJewSinceJC 700 Posting Maven

You get that error because you can't update SWT widgets from anywhere except the SWT Thread. In order to fix this, see these methods:

asyncExec
syncExec

Go to this link, search for "The syncExec() or asyncExec() Methods Do Not Create Threads" and then read everything from there down. They have a code example as well.

BestJewSinceJC 700 Posting Maven

Adity, as I said before, it has been awhile for me. My understanding of a Perspective in Eclipse is that it is a collection of views, whereas a view is basically one window container. Given this information, the following might also be helpful to you:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(String viewID)
BestJewSinceJC 700 Posting Maven
PlatformUI.getWorkbench.showPerspective(perspectiveID, window)

It has been many months since I worked on Eclipse RCP .. but I think that is the correct way to do it. If you look at the methods available to you in the PlatformUI class you can trace those method calls yourself.
http://publib.boulder.ibm.com/infocenter/rsdhelp/v7r0m0/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/PlatformUI.html

BestJewSinceJC 700 Posting Maven
  • Use informative variable names. As an example, "doAgain" is a bad variable name because it tells us nothing about when and in what circumstances you want to "do something again".
  • In your getmeters method, if the user enters invalid input, your program will crash. You should use a try catch.
  • getmeters should be getMeters. It is just convention, use camelcase.
  • Most people would consider naming a variable showOptions and naming a method showOption() a bad idea. It is confusing to look at.
//This doesn't make sense!
while (option != 4) option = 0;
//Use this instead!
if(option != 4) option = 0;

And furthermore, why would you want to do that to begin with? Comments could help a lot here. What is option 4, what is it supposed to do, and why do you want it to be option 0 instead?

Chunks of code like the one below should not be in main(), they should be in their own method:

// Allow user to quit the program
			yesOrNo	= JOptionPane.showInputDialog(
			"Do you want to perform\n" +
			"another calculation?\n" +
			"Enter 'y' for yes or\n" +
			"'n' for no.");

			if ((yesOrNo.equals("Y")) || (yesOrNo.equals("y")))
						{
							doAgain = true;
						}

						else if ((yesOrNo.equals("N")) || (yesOrNo.equals("n")))
						{
							doAgain = false;
						}

						else
						{
							JOptionPane.showMessageDialog(null,
									"Invalid input.  Try again.");
						}

			}

You should make a method to ask the user whether or not they want to quit the program. Then your main method would look more like this:

main(String[] args){ …
BestJewSinceJC 700 Posting Maven

Repost your up to date code. And I just noticed you're using

option = Integer.parseInt(keyboard.next());

when it would be more intuitive to use

option = keyboard.nextInt()

You should also consider rewriting some of your code for modularity. For example, you have an entanglement of loops and if statements - as a code reviewer, I'm not even sure what you're trying to do. I'm going to repost the code that you showed me earlier to show you how modularity can make your code easier to read and less spaghetti looking.

BestJewSinceJC 700 Posting Maven

Dani and Narue are the same person. My evidence is that they are both women. I submit this to all of you so you can congratulate me.

BestJewSinceJC 700 Posting Maven

You should only init your JTextFields once in the entire program. Therefore, it doesn't make sense to call initJTextFields from within your showKey method. You should init the JTextFields when the GUI is first created, then you should .add() them to your JPanel.

Here is an example to help you. Notice in the example that in the actionPerformed method, I create a new JTextField. Without that line, the example would have worked. There is no reason to create a completely different JTextField (using new) after the point when you add it to the JPanel:

public class ExampleGUI {
	static JTextField field = new JTextField("Blank");
	static JFrame frame;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		frame = new JFrame();
		JPanel panel = new JPanel();
		frame.add(panel);
		panel.add(field);
		
		field.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent arg0) {
				//Comment the next line and this example will work. This way, it doesn't.
				ExampleGUI.field = new JTextField();
				ExampleGUI.field.setText("Bleh");
			}
			
		});
		
		frame.setSize(300,300);
		frame.setVisible(true);
	}

}
BestJewSinceJC 700 Posting Maven

You shouldn't use a try catch to make sure that the user enters a positive number. You should use a try catch to prevent error conditions from crashing your program. Entering a negative number is not an error condition. An example of an error condition would be attempting to parse an int when the user entered a String (for example, see the code below)

try{
int value = Integer.parseInt("This String can't be parsed as an int! It'll cause an Exception!");
} catch(Exception e){
System.out.println("womp womp.");
}

To answer your original question, whether or not you can combine the two try catches depends on how you declare the catch statement. For example, an "Exception" will catch more errors than a NumberFormatException because an Exception is less specific (that is, more things fall under the category of 'Exception'). However, having more specific types like NumberFormatException is useful because the error message will be more clear -- it'll tell you more precisely what has gone wrong with your program. So you should balance these two needs carefully. In most cases, I would recommend using the specific type of Exception (for example, since the parseInt() method that I showed you above throws a NumberFormatException if there is an error, you should therefore use a NumberFormatException in the catch block). However, sometimes you may just want to catch any Exceptions in which case just use Exception and put all of your code into the same try block. I hope that helps.

BestJewSinceJC 700 Posting Maven

I use the version I linked you to - Eclipse for Java Developers. And no, there are no issues that I know of with using it for Windows 7 (which is what I'm using right now).

BestJewSinceJC 700 Posting Maven

Read this article. If you have any questions after reading it, post them.

BestJewSinceJC 700 Posting Maven

1. You never declared the variable "option". You can't use a variable that was never declared.
2. You never declared the variable "keyboard". You used the statement "keyboard.next()" which implies you wanted to use keyboard as if it was a Scanner Object. Somewhere before that line, put this line:

Scanner keyboard = new Scanner(System.in);

3. Where you have the comment that says "End while (do again)", you don't have enough closing brackets. You need to add another } after that line.

I think an IDE like Eclipse might be very helpful to you. It took me only a few seconds each to spot all of your errors while using Eclipse - it highlights things like undeclared variables and not using the correct number of closing brackets for you.

BestJewSinceJC 700 Posting Maven
public class YourMainClass{

public static void main(String[] args){
// Up here you created your arraylist and put Location objects in it
new YourGUI(yourArrayList);
}
}

That is all you need to do. Let the YourGUI class handle putting the ArrayList inside the JList and then showing the GUI. Here is a good tutorial on how to use JList

BestJewSinceJC 700 Posting Maven

http://www.daniweb.com/forums/announcement9-3.html

Click the button that says "(code)" on the reply box. Put your code inside of the two tags that will show up. I thought you already knew this because your previous posts in this thread used code tags..

BestJewSinceJC 700 Posting Maven

Please use code tags. Just go back and edit them into your post.

BestJewSinceJC 700 Posting Maven

I've never seen anybody do something like "return main()" before. Use a while loop instead if you are trying to get the effect of looping.

BestJewSinceJC 700 Posting Maven

Define a GUI class that has a constructor which takes an ArrayList<Location> as its argument.

public class YourGUI{
public YourGUI(ArrayList<Location> list){
//add it to a JList here, add that JList to a JPanel & JFrame, show the JFrame, etc
}
}

Your project statement seems quite complicated so I find it very likely that you already know the information I just gave you. Is there any particular reason why you need to "unpack" the ArrayList? If you have an ArrayList of Location Objects... and the Location Objects contain readable information (such as Strings) then it should be ok.

Oh, and I forgot to mention: after you finished setting up this GUI class, from within your "main" class (where you have the ArrayList you were discussing) you would create a new YourGUI(arrayList) and that would be it.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

http://blogs.msdn.com/excel/archive/2008/04/10/understanding-floating-point-precision-aka-why-does-excel-give-me-seemingly-wrong-answers.aspx

Probably a precision problem. There is no error, it is just a side effect of using binary digits to store certain values.

BestJewSinceJC 700 Posting Maven

Example of the SMTP Procedure

This SMTP example shows mail sent by Smith at host Alpha.ARPA,
to Jones, Green, and Brown at host Beta.ARPA. Here we assume
that host Alpha contacts host Beta directly.

S: MAIL FROM:<Smith@Alpha.ARPA>
R: 250 OK

S: RCPT TO:<Jones@Beta.ARPA>
R: 250 OK

S: RCPT TO:<Green@Beta.ARPA>
R: 550 No such user here

S: RCPT TO:<Brown@Beta.ARPA>
R: 250 OK

S: DATA
R: 354 Start mail input; end with <CRLF>.<CRLF>
S: Blah blah blah...
S: ...etc. etc. etc.
S: <CRLF>.<CRLF>
R: 250 OK

The mail has now been accepted for Jones and Brown. Green did
not have a mailbox at host Beta.

Reading this should clarify how the reply codes work, which will help you debug your project.
http://james.apache.org/server/rfclist/smtp/rfc0821.txt

BestJewSinceJC 700 Posting Maven

Because you linked us to an entire document instead of summarizing what you're trying to do and why you're having trouble. Anyway, I looked through it for you, all you should need to do once you're finished is send an email to your school email address. If it eventually gets there your project worked. If not your project probably doesn't work. .

Oh, and your teacher gave you the list of SMTP reply codes for a reason. Once you successfully send a message to the server, it is going to send you back a certain reply code. Therefore, if you get back this reply code, you have successfully sent a message to the server.

BestJewSinceJC 700 Posting Maven

Nah, I got those links from Salem. :)

BestJewSinceJC 700 Posting Maven

That is because you never called any methods that would add text to the JTextPane. See this tutorial on Text Panes. Furthermore, your addTextToTextPane method returns a JTextPane which is unnecessary. Since your JTextPane is an instance variable, your addTextToTextPane method should just be declared as returning void.

BestJewSinceJC 700 Posting Maven

Never used it, looks simple enough though

http://www.jasypt.org/

BestJewSinceJC 700 Posting Maven

Read about strtok which tells you what function to use to separate a string into tokens. Then use atoi to try to parse the string as an int.

BestJewSinceJC 700 Posting Maven

It's because acctNum was never initialized (i.e. you never said new JLabel())

BestJewSinceJC 700 Posting Maven

No problem, just let me know if you need any more help.

BestJewSinceJC 700 Posting Maven

It looks to me like you're using DataInputStream and FileInputStream properly. Where are you getting stuck? Is it doing anything from the setText line?

BestJewSinceJC 700 Posting Maven

Whew, for some reason I confused C with objective-c .. of course the array isn't an Object and doesn't have 'size' or 'length'. I feel silly - Next time I'll compile first. Neat trick WaltP.

edit: just so the OP doesn't copy paste, there is a typo in Walt's snippet, the second == should be =

BestJewSinceJC 700 Posting Maven
for (side3 = 3; side3 <= 3; side3++)

has no effect whatsoever other than setting side3 equal to 3. As far as looping, it does nothing.

BestJewSinceJC 700 Posting Maven

If you want great sound quality, buy Bose products :)

BestJewSinceJC 700 Posting Maven
int i;
for (i= 0; i < array.length; i++){
if (array[i] == '\0') array[i] = '\n';
}

My C coding skills are very rusty but that is the general idea, you might have to tweak it a little bit to make it compile haha (I don't remember if C uses .size or .length for arrays..).

BestJewSinceJC 700 Posting Maven

Thank you guys for your helpful responses.

BestJewSinceJC 700 Posting Maven

Because your method definition is wrong.

public void setEmployee(ArrayList Employee)

You defined your setEmployee method as taking an ArrayList Object, not as taking an Employee Object. It should be

public void addEmployee(Employee emp)

And notice I changed the name from set to add, because what you're doing is adding an Employee to the ArrayList, not setting the ArrayList. You should also read through this tutorial because your current assignment is going to be nearly impossible for you to get done unless you read about the topics in that tutorial.

BestJewSinceJC 700 Posting Maven

No Offense but I think you should find yourself a new volunteer job. You are abs. no help at all. I don't expect you to do my homework but at least you should be able to tell me what I am doing wrong and I will try to fix it myself hence volunteers that help. Thank You for all your help. Have a nice day!!!!!!!!

http://catb.org/~esr/faqs/smart-questions.html#code
http://catb.org/~esr/faqs/smart-questions.html#urgent

In my previous post, I was trying to get you to give more information so that I could help you without spending an exorbitant amount of time figuring out why your code is not working. That is your job. The least you can do is tell us what part of your assignment you're stuck on, why you haven't been able to proceed, what errors you are getting (if any), how far your program gets, and what causes the program to fail. If you cannot give us this information then you have not tried and I do not care whether or not you finish your assignment. And "telling off" people like myself who are just trying to help you is very likely to result in nobody helping you with your problem at all.

Ezzaral commented: More of an explanation than they deserved. +10
BestJewSinceJC 700 Posting Maven

Because you said

ArrayList<String>

instead of

ArrayList<Employee>

. Your code won't work anyway, though, because your ArrayList is in the wrong place. Your ArrayList of Employees should be an instance variable in your Project class. That means it should look something like this:

public class Project{
//Variable Declarations..
ArrayList<Employee> empArrayList = new ArrayList<Employee>();
//Methods go down here..
}
BestJewSinceJC 700 Posting Maven

When you create a new Employee, you would just say something like

Employee emp = new Employee();
yourArrayList.add(emp);

See the javadoc for arraylist. If your Assignment class needs to be able to list the Projects that are available, then the Assignment class should probably have an ArrayList of Projects. If you need to be able to list what Projects an Employee is involved in, assuming your Project class has an ArrayList of Employees you can use the following:

//Assuming projectsList is an ArrayList of your Projects and someEmployee is
//an Employee Object..
for (Project proj: projectsList){
if (proj.employeesList.contains(someEmployee)){
System.out.println("The employee is part of the project " + proj.projectName);
}
}

One more thing: in order to search for an Employee in any type of Collection (i.e. an ArrayList, etc) you must override the equals() method.

BestJewSinceJC 700 Posting Maven

I agree with closing old threads automatically. If someone has a related question a year later they can make a new thread. The downside (as Vernon mentioned) is losing some good points if someone has something useful to say. But that is a rarity compared to how many times spammers up old threads or people post irrelevant code in them.

BestJewSinceJC 700 Posting Maven

You said System.out.println(s) which prints your Scanner Object. Shouldn't you be saying

System.out.println(test.toString());
BestJewSinceJC 700 Posting Maven

Your Project class should have an ArrayList (or some data structure) to hold Employees in it. That way you will know what Employees are working on what project. As far as the Assignment class, I don't really understand what your teacher has in mind for what an Assignment actually is. Ok so it has a start and stop date. . so what? What else does an Assignment have? What exactly is an Assignment in this context?

BestJewSinceJC 700 Posting Maven

Jtodd, stultuske has already provided you with the correct information. . if you take a look at the Javadoc for Random, you'll see that there is a method defined as "public int nextInt(int n)" that will be helpful in doing what he suggested. Again, the trick is to have that method generate an int for you between 0 and the size of your array. Then you use the int that it returns in order to index your array.

One more thing - by convention, variable names are not capitalized. Only class names are capitalized. (i.e. where you named your variable Number you should probably name it number).

BestJewSinceJC 700 Posting Maven

1. Explain exactly what you are stuck on.
2. Explain why you are stuck. This information might include what inputs make your program fail, what section of your program is failing (with line numbers), etc.