verruckt24 438 Posting Shark

Keep the method name as it is. I was just suggesting change in the variable name.

What I mean here is

public static double calcFV(double p, double r, double t)	
   	{
   			double value1 = p; // assign the variable p to principle
  			double value2 = r; // assign the variable r to rate
  			double value3 = t; // assign the variable t to years
   		
   		double futureValue = p * Math.pow( (1.0 + r/100), t);
   		return futureValue;
	}

Also keep the call to the method in the println statement unchanged

System.out.println("Your investment will be worth approximately: " + calcFv(p,r,t));

I think you have got yourself confused with method and variables. As ~s.o.s~ has mentioned read some java tutorials like this one and practice some more examples to get things sorted out.

verruckt24 438 Posting Shark

Instead of

double Math.calcFV = p * Math.pow( (1.0 + r/100), t);
    return calcFV;

Do it this way

double futureValue = p * Math.pow( (1.0 + r/100), t);
    return futureValue;
verruckt24 438 Posting Shark

For this you would have to implement the ChangeListener Interface's stateChanged() method, which would be invoked whenever the tabbed panes state has been changed, which includes the changing of the active tab from one to another.
When this happens, you can use the getAccessibleContext() method to get the name of the currently active tab.

Check the JTabbedPane & ChangeListener docs for more.

verruckt24 438 Posting Shark

Wow, if not for the 'Location : India' I would have started believing that ~s.o.s~ woould be the username of Mr. James Gosling himself, that was so good. :)

Just to add a thing, yes static objects can be called by instance names too, I just meant that non-static members cannnot be called without the current object's reference.
Also, static members can certainly exists even without a single instance existing.

verruckt24 438 Posting Shark

Please ignore the above post as it is an intermediate version of this post, where I accidently clicked on the save button.

Yes, so as I said the scan was indeed creating problems weren't it ? It had to.

As far as this error goes "non-static variable input cannot be referrence from a static context"
If you declare the input variable in the main method I think it should clear up the errors. Also since you are not using this variable elsewhere, it should not cause problems.

So instead of

public class HW02_jsn
{
    Scanner input = new Scanner(System.in);
    public static void main(String[] args)
    {
     // code
    }
}

You would need to do this

public class HW02_jsn
{
    public static void main(String[] args)
    {
    Scanner input = new Scanner(System.in);
    // other code
    }
}

To just explain you something about the 'static' keyword, 'static' means something that is for the entire class rather than for an instance. You might have heard or would hear member variables being called instance variables. This is because, for variables that aren't declared 'static' exists for each instance of the class. So, for e.g. a class Square might have side , which would specify the length of the side, as an instance variable, since each Square object might have different lenght of it's side, so each instance needs to have a side variable of it's own.
But Square, the class, might have a static noOfSides variable, which …

verruckt24 438 Posting Shark

Okay, after reading your post, you appear to me as someone really wanting to learn. Thats good. Keep Up.
Firstly, you can certainly post the instructions you have been given for the assignment it would only help us help you. The only thing this forum does not like is people posting assignments instructions and asking members to code it for them, so as long as you are not doing that, it's fine.
Secondly, all the errors sited by you are because of the method declaration within the method, I think if you remove that most of your errors will certainly vanish.

Also about the 'static' methods part, I guess a little reading about the static keyword would be of much help. Where and when should the static keyword be used is of prime importance for it to be used.

EdIt : I had this page opened and then went away, so couldn't see your most recent post.

verruckt24 438 Posting Shark

Use code tags for posting your code, it just make the code more readable.

Some of the errors that I see here are :
1. You haven't declared what scan is. I guess you are supposed to use input here but you have used scan .

public static double calcFV(double p, double r, int t)
{
double value1 = p; // assign the variable p to principle
double value2 = r; // assign the variable r to rate
int value3 = t; // assign the variable t to years

int calcFV(double p, double r, int t)
{
int fv = p * Math.pow( (1.0 + r/100), t);
return fv;
}

Here you have defined a method within another method having the same name but a diffrent signature. I am unable to gather what you are trying to achieve here.

Also I see all of you methods being static, can you explain the purpose of that ? I guess since you are calling them from main which is a static method, you have made all the other methods static too. Is it ?

Also post what errors you are getting.
Lastly since you say you are a begginner in java there is a wonderful sticky thread at the start of this forum, that would be helpful for you.

verruckt24 438 Posting Shark

You need to use a JTextArea for this, you can specify the no. of rows and columns for the JTextArea by using the methods setRows() and setColumns() . When you set the JTextArea's rows and columns to more than the width and height assigned for the JTextArea horizontal and vertical scroll bars appear automatically when the text in the area runs beyond it's width (or height).

To save the text within the JTextArea into a file on the click of a button, you would need to write the code that is invoked on the button press, which writes the content of the text area to a file.
The content of the text area can be received by using the getText() method.

The button press can be detected by adding an ActionListener to the button.

I hope this helps, here are the Java docs for the JTextArea.

verruckt24 438 Posting Shark

If your friend really wants to learn, tell him to start some serious reading. A lot of beginner resources are mentioned in the sticky; starting with the Java beginner tutorials ain't that bad an idea.

@christiangirl
Thats what my point was when I said tell your friend to look at other places. But Alas !!!

Also talking about the code it isn't arranged in the best of the manners, quite the opposite infact, which even though is written by him does not seem to be adviced to be changed, by you. Also not only Math4 but none of your classes have an addButton() method and you have used it in all of them, which makes me conclude that you yourself might be not knowing about these things. Then what's the point in tutoring about something that you yourself are in the learning phase of. Wouldn't you be teaching something incorrect to him, may be even accidentally.

My next point was about delaying the entire process of getting to the solution by not directing him towards resources directly. Didn't you prove my point with your next post ?

Sorry it took me longer to post the errors, I didnt see that someone else had replied.

verruckt24 438 Posting Shark

The helper himself needs help ? Better tell the student to look at other places for solution I guess that way he would reach the solution faster. Why follow a bigger loop of he asking you and you asking us, that way he won't be able to understand how one got to the solution ain't it true ?

verruckt24 438 Posting Shark

While specifying the foreign key constraint you have specified "ON UPDATE NO ACTION" while this seems to mean that no action would be taken on update, it specifically means that you will not be allowed to update too, either remove the clause or if it is binding for you to have it, modify it suitably.

verruckt24 438 Posting Shark
private JRadioButton male;
private JRadioButton female;
private ButtonGroup gender;

// create the radiobuttons
male = new JRadioButton();
female = new JRadioButton();
gender = new ButtonGroup();

// set the necessary parameters for the radio buttons
male.setText("M");
male.setSelected(true);
female.setText("F");
female.setSelected(false);

/*
*can be used to catch the button on which the event is generated  * (by checking the action commad)
*/
male.setActionCommand("Male");
female.setActionCommand("Female");

// finally add the two buttons to the 'gender group'
gender.add(male);
gender.add(female);
verruckt24 438 Posting Shark

1. I don't see anything wrong with the query code here.
2. If you want to send the data for just two variables mention just those variables in the insert into clause for e.g. if you want to insert just date and time write the query as follows : INSERT INTO tablename(date,time) values ('%datevalue%','%timevalue%'); this will work just as fine.
3. Instead of having two independent columns, one for date and the other for time you caould have a single datetime or timestamp column. Look into the specs of each to find out which one is more appropriate in your case.
4. Since InvoiceNum is an auto generated column, you need not pass data for it (I assume it is something like AUTO_INCREMENT in MySQL) you can omit this coulmn name and it's corresponding value from the query.

Alsoyou have not stated what error as such you are getting, mention that to get more specific help.

verruckt24 438 Posting Shark

Yes in this case you would have to use an instance variable for the flag instead of the static variable since, as pointed out in earlier posts static variable specifies a attribute of the entire class you won't be able to distinguish between two instances of the same class using it.

verruckt24 438 Posting Shark

Before moving further I would like to clear certain details. Since the static field would be common across multiple instances of a class, what if two different instances were initialized through diffrent constructors, in that case your serialization/deserialization would always depend on the last instance created. Would this be proper behaviour according to the logic of your problem or would not be ?

On second thoughts is this the question you are asking meaning is this what you mean by static field not preserving it's value ? (I have not clearly understood your question) if yes, then in that case you can use an instance variable instead of a static variable and have the serialization/deserialization behaviour depend on that.

verruckt24 438 Posting Shark

@BestJewSinceJC : While it is certainly possible to decompile class files and you would certainly get several decompilers, one of which is the DJ Java decompiler, I would like to point out a thing here. The source code thus obtained would not be an exact copy of your .java file. Variable names would be changed and even the constructs used for looping might be changed (this is a personal expierience, my while loop was changed to a do-while loop) which would though certainly not change the logic of the program but make it quite complex in figuring out what you've written previously, when you need to make any further additions to your program in the future. While on the other side when you do make these changes by hand you would certainly have an original copy of the source code with you at all times for future needs.
All this to make a point that though decompiling is an option, I would rather prefer to make the changes by hand if I have the changed logic and the corresponding langauge changes quite clearly in my mind.
This is the thing every developer dreads, all the best for whatever option you choose.

EDIT : stephen84s has suggested a good option too... Hope you are on windows and hope you don't have to take any of the 'decompile' or 'write changes again' option....

verruckt24 438 Posting Shark

ignore this post if you intend to actually learn something. start off with Notepad. it's not the most "flashy" tool, but it's as good as any idea (for a beginner that is, and it's even better)

look up the java syntax, re-read your notes on "how to create objects" and give it a go.
if it doesn't work, come back here with your own code and show us that, we'll help you out from there.

ditto, not only is the solution mentioned here by quuba irrelevant in this case it is also wrong in the case that it would apply. Using an IDE just because you don't or don't want to remember langauge syntax and API is totally useless, it should rather be used to assist in your development when much of the basic work is very well known to you and you need to waste your time repeating that.
As a personal suggestion IDEs should never be used unless until you have spent enough time typing the actual langauge, this way you will remember & learn more.

verruckt24 438 Posting Shark

Reading this would give you a detailed idea of the things you want. All the topics of interest are listed there.

verruckt24 438 Posting Shark

If your problem has been solved, please mark the thread as solved. So that anyone else visiting is aware of the fact.

verruckt24 438 Posting Shark

IT depends on if your program has something to offer for others. An API offers an abstraction for some low-level tasks while doing some higher level tasks. Let me give you an example of address book itself (since your program dela with it) An address book has contacts which can be created, edited and deleted. Further more it is also supposed to offer functionality such as searching of a contact. Now if you write a collection of classes that provide this basic functionality like say you store contact's using a List and implement the create, edit, delete and search functions. Meaning you provide the most general address book operations through your classes so that developers, using your library, might be able to implement an AddressBook feature without worrying about the details of create, edit and delete (they just call your functions) then you might be able to say that you have provided an API for an AddressBook.

Now deciding whether your program is an API or not is pretty straight forward.

verruckt24 438 Posting Shark

I assume here you want to run the above command from java.
Java provides you with facilities to run commands at shell/prompt with the Runtime.exec() function
It should be something like this :

String cmd = "C:\Program Files\aProgram\test.exe -login joeSmith password1";
Runtime run = Runtime.getRuntime();
Process proc = run.exec(cmd);

Also see this (E.g. From Java Developer's Almanac)

verruckt24 438 Posting Shark

That's exactly what I'm doing by posting on Daniweb. Not out of laziness, but I was short on time and I was fairly sure I would have follow up questions, so I chose to post here. Since I probably answer more questions than I ask, I'm sure you guys will forgive me. :) Its a shame that when I mark this thread solved, you will now get credit for it, although you didn't answer the question or offer an alternate solution. Either way, thanks to Masijade.... an alternate solution is just as good.

I did not mean to hurt you at all although you took it in a negative way, what I just meant was you could have found the solution googling it rather quickly than on this forum also it would have been in detail which I thought you would be wanting to know since your question was so specific and all this would just add up to your knowledge about the question domain thats it.
As far as the credit goes you can may as well request the moderator or whosoever has the power to, to not to add this thread to my solved threads (or subtract the count, if it can be done so) since as matter of fact I too don't like to take credit for the stuff I haven't actually contributed to.

verruckt24 438 Posting Shark

the path should inclulde the bin directory too. so just include C:\Program Files\Java\jdk1.6.0_10\bin instead of what you have now.

verruckt24 438 Posting Shark

Use the power of the Internet to find it out....

verruckt24 438 Posting Shark

If you are able to detail what exactly are you trying to do by attempting to return the integer I think we could be of more use to you.

verruckt24 438 Posting Shark

If you are a beginner and would really like to take your skills to the next level, I recommend you use an Editor that offers the most basic capabilities, since it has been a personal observation that the more advanced IDEs people tend to use the more dependent they become on the IDE for the most basic of tasks.
Once you have reached a certain level of programming maturity and want to exploit the features that modern IDEs offer you can choose from among the many available. Since these have already been named here I won't repeat their names.

Having said that if you looking towards more advanced programming such as Swing GUI creation and stuff you would have to look at these right away.

verruckt24 438 Posting Shark

And I'm not going to post any more on this because of some other things that I believe.
No matter you win or lose a rat race you 'd still be a rat.
You can continue as long as you want, I'm here to do other more meaningful things.

verruckt24 438 Posting Shark

no, I didn't, but you just answered it yourself:

I'had thought you'd give some intelligent answer just as I gave to yours, but instead you are just copy-pasting my answers after I have put them in your face. You know it's so easy to appear intelligent when parroting intelligent people. ;)

Ezzaral commented: This is not constructive here. -3
verruckt24 438 Posting Shark

I never claimed to have delivered the most perfect code. I just based myself on his code and explained where he went wrong.
It's not my job to re-write his code to the most efficiënt form, it's his own task to find out whether or not there is a better way.

But atleast you can guide someone correctly if you are guiding someone at all. Do not guide someone wrongly.

And I hope now you get the answer for the extra '{' that you were commenting upon in the other thread. :D

verruckt24 438 Posting Shark
if(num=='8')
    pluralName="Eighty";
if(num=='9')
    pluralName="Ninety";
else
    pluralName="Error /w Plural Method";

this will always return "Error /w Plural Method", unless the value for num == '9'
what you want to do (and not only for the '8' check) is using nested if's

if(num=='8'){
    pluralName="Eighty";
}
else{
    if(num=='9'){
        pluralName="Ninety";
    }
    else{
        pluralName="Error /w Plural Method";
    }
}

This is a weak example of actually implementing it the right way, it should have been done using switch-case statement and using break as correctly pointed out by the above post. Also this method is far unoptimized since it would check for every 'if' till the num=='8' even if the very first 'if' statement is true. I don't think you want your program to check every condition on every occassion even if the very first condition is true in many of those occassions. ;)

verruckt24 438 Posting Shark

There's no better way to explore and understand the Java language then to go through the javadocs, it helps you tremendously (Thats my opinion ;-))

verruckt24 438 Posting Shark

Could you detail a bit more.

verruckt24 438 Posting Shark

But for that to be an actual CSV file it should have different values separated by commas. Are you separating out values using commas ?