|
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.
|