Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 14th, 2004, 8:35 AM   #1
cody
Newbie
 
Join Date: Apr 2004
Posts: 1
Rep Power: 0 cody is on a distinguished road
I see this board is very young. Well I'm a high school freshman in a java programming class and i have a little problem with my homework.

My source code is:

-----------------------------------------------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;

public class DogsHumanAge extends JApplet
implements ActionListener


{
JTextField inputHumanyears, displayDogyears;

public void init()
{

JLabel labelHumanyears = new JLabel("Enter the dog's age in human years:",
SwingConstants.RIGHT);
inputHumanyears = new JTextField(5);

JLabel labelDogyears = new JLabel("Dogyears = ", SwingConstants.RIGHT);
displayDogyears = new JTextField(5);
displayDogyears.setEditable(false);
JButton go = new JButton("Compute age");
go.addActionListener(this);

Container c = getContentPane();
c.setBackground(Color.white);
JPanel p = new JPanel();
p.setLayout(new GridLayout(3, 2, 5, 5));
p.add(labelHumanyears);
p.add(inputHumanyears);

p.add(labelDogyears);
p.add(displayDogyears);
c.add(p, BorderLayout.CENTER);
c.add(go, BorderLayout.SOUTH);
}

public void actionPerformed(ActionEvent e)
{
int Humanyears = Integer.parseInt(inputHumanyears.getText());
double Dogyears = calculateDogyears(Humanyears);
DecimalFormat df = new DecimalFormat("00.0");
displayDogyears.setText(df.format(Dogyears));
}

private double calculateDogyears(int Humanyears, int Dogyears)
{
return 13 + (int)(16.0 / 3.0 * (Dogyears - 1));
}
}

-----------------------------------------------------------------------------------------------

The error message i get is:

DogsHumanAge.java:42: calculateDogyears(int, int) cannot be applied to (int)
double Dogyears = calulateDogyears(Humanyears);


The intent of this program is to calculate the number of dog years from the given human years that is inputted into the input box.
cody is offline   Reply With Quote
Old Apr 14th, 2004, 8:18 PM   #2
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,630
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
well im not 100% sure what the problem is but a buddy of mine was thinking it was the (int) in this line
private double calculateDogyears(int Humanyears, int Dogyears)
{
return 13 + (int)(16.0 / 3.0 * (Dogyears - 1)); *<-- this line :)
}

try removing that and see what it does for you. i didnt try running your code, but when i get time i will try it out. hope this helps
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is online now   Reply With Quote
Old Apr 15th, 2004, 11:34 AM   #3
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
Your problem is that you are not using the correct form of calculateDogYears(). You define the method as calculateDogYears(int,int) but only called it with one arg.

Error:
Chicken-of-the-PowerBook:~/devel/java jowings$ javac DogsHumanAge.java
DogsHumanAge.java:42: calculateDogyears(int,int) in DogsHumanAge cannot be applied to (int)
double Dogyears = calculateDogyears(Humanyears);
         ^
1 error

I would guess that you meant to do something like this:
private double calculateDogyears(int Humanyears)
{
   return 13 + (int)(16.0 / 3.0 * (Humanyears - 1));
}

//SIDEBAR: please use the CODE tags when posting code. It makes things so very much easier to read.
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC