我在代码中导致错误的公式是为赋值给出的公式 [英] The formula that I have in my code which is causing the error is the formula that was given for the assignment

查看:74
本文介绍了我在代码中导致错误的公式是为赋值给出的公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//我收到的错误消息是找不到符号方法第二(双)" 但我感觉好像我已经确定了一切. (我显然错了).我认为公式也有问题,但这就是我为公式提供的代码.任何帮助将不胜感激.

//The error message I'm getting is saying "cannot find symbol- method second(double) but I feel as though I have identified everything already. (I'm clearly wrong). I think there is a problem with the formula as well but that is the code I was given for the formula. Any help would be greatly appreciated.

    import java.util.GregorianCalendar;
    import javax.swing.JComponent;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import java.awt.*;//import * Class

    public class ClockComponent extends JComponent
    {

        double hour;
        double minute;
        double second;

        public void setCurrentTime()
        { 

            GregorianCalendar calendar = new GregorianCalendar(); 


            hour = calendar.get(calendar.HOUR_OF_DAY);
            minute = calendar.get(calendar.MINUTE);
            second = calendar.get(calendar.SECOND);
        }   

        public void paintComponent(Graphics g)
        {
            Graphics2D g2 = (Graphics2D) g;

            int xCoord = 40;
            int yCoord = 25;



            Ellipse2D.Double clockFace = new Ellipse2D.Double(xCoord, yCoord, 700, 700);      
            g2.setColor(Color.black);
            g2.draw(clockFace);
            g2.fill(clockFace);



            g2.setColor(Color.red);
            Font font1 = new Font("Old English Text MT",Font.BOLD,30);
            g2.setFont(font1);
            g2.drawString("John Doe", 305, 680);



            g2.setColor(Color.yellow);
            Font font2 = new Font("Arial",Font.BOLD,30);
            g2.setFont(font2);
            g2.drawString("III", xCoord + 670, yCoord + 355);
            g2.drawString("VI", xCoord + 340, yCoord + 685);
            g2.drawString("IX", xCoord + 10, yCoord + 355);
            g2.drawString("XII", xCoord + 340, yCoord + 35);



            int xCenter = 380;
            int yCenter = 380;

            double secondHandLength;
            double minuteHandLength;
            double hourHandLength;

            double xSecond = xCenter + secondHandLength; cos(second (2*Math.PI/60));
            double ySecond = yCenter - secondHandLength; sin(second (2*Math.PI/60)); 

            double xMinute = xCenter + minuteHandLength; cos(2*Math.PI/60);
            double yMinute = yCenter - minuteHandLength; sin(2*Math.PI/60);

            double xHour = xCenter + hourHandLength; cos(2*Math.PI/60);
            double yHour = yCenter - hourHandLength; sin(2*Math.PI/60);



            g2.setColor(Color.blue);
            Line2D.Double secHand = new Line2D.Double(xCenter,yCenter,xSecond,ySecond);
            g2.setStroke(new BasicStroke(1));
            g2.draw(secHand);


            Line2D.Double minHand = new Line2D.Double(xCenter,yCenter,xMinute,yMinute);
            g2.setStroke(new BasicStroke(7));
            g2.draw(minHand);


            Line2D.Double hourHand = new Line2D.Double(xCenter,yCenter,xHour,yHour);
            g2.setStroke(new BasicStroke(13));
            g2.draw(hourHand);
        }
    }

推荐答案

这可能不是您想要的:

(second (2*Math.PI/60))

Java将把second当作方法调用,因为它紧随其后的是一个开放式括号,其中有一些值.由于该功能不存在,因此Java会产生该编译错误.

Java is going to treat second as a method call, as it is immediately followed by an open-paren, with some value in it. Since that function doesn't exist, Java produces that compilation error.

如果要获取两者的乘积,则必须显式提供乘法运算符.

If you were trying to get the product of the two, you have to explicitly provide the multiplication operator.

(second * (2*Math.PI/60))

现在我有一点时间来研究它,这些陈述也没有意义:

Now that I've had a moment to look at it, these statements also don't make sense:

double xSecond = xCenter + secondHandLength; cos(second (2*Math.PI/60));

假设对cos的调用是有效的,则secondHandLength在任何地方都没有定义.此外,您会将计算结果放在地板上,这不是您可能打算做的.我不确定它们的合理值,因为它们似乎与圆的余弦无关,但是需要定义这些变量.

Assuming the call to cos was valid, secondHandLength isn't defined anywhere. What's more, you're dropping the result of your calculation on the floor, which isn't what you likely intend to do. I'm not sure what a sane value would be for them, since they seem independent of the cosine of a circle, but those variables need to be defined.

这篇关于我在代码中导致错误的公式是为赋值给出的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆