Programming Forums
User Name Password Register
 

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

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

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 12:20 AM.

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