Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code problem.

 
fan tung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i was trying to do temp. conver from f to c.
here is my part of my code. please help me.
/* Insert the method's description here.
* @param e java.awt.event.ActionEvent
*/
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == calcul)
calculate(fahTF.getText());

if(e.getSource() == reset)
{
fahTF.setText("");
celTF.setText("");
}
}
/**
* Insert the method's description here.
*/
public void calculate(double fah, double cel)
{

???
cel = (5/9 * (fah - 32));

}
and i got this compile error:
FrameTest2.java [78:1] calculate(double,double) in FrameTest2 cannot be applied to (java.lang.String)calculate(fahTF.getText());

thanks in advance.
fan
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method calculate has two formal parameters (double, double), you are calling calculate with one argument which looks like it could be a String.
 
fan tung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you show me how to fix that?
thank you so much!
fan
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually that is only the first of you problems. From the code you posted it appears that you are trying to pass back the answer, "cal", as a parameter. That will not work in java. You need to pass it back as the return value.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
fan tung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks William.

"I think Willims is right."(at least this time)
 
Jem Edwards
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fan tung:
It looks like you're working on the same problem that I'm working on!
Are you taking Introduction to Programming also?
I'm taking it via a web class and it's just like working alone - there's no class participation on the boards so besides reading this horribly boring book I also surf the web for easy to understand study guides.
In fact I found a site that explained increment & decrement operators better than the book cuz I just wasn't gettin' it.
Good Luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic