.class预期,我需要添加什么才能编译?

时间:2014-02-25 19:09:02

标签: java

我收到的错误是在我的第二个类中是“.class”,这是Driver类。

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Shape;

    /**
     * A Circle is a figure that has a radius, a circumference, 
     * and an area. 
     * @author Kelvynn Cayanan 
     * @version 02/09/2014
    */
    public class Circle
    {

        // Constants
        public static final double pi = 3.1415926; 

        // instance variables
        private double circumference;
        private double area; 
        private double radius;
        private Color color;
        private int xLeft;
        private int yTop;

        /**
        * Positions the circle at the top left.
        */
        public Circle(int x, int y)
        {
            xLeft = 10;
            yTop = 10;
        }

        /**
        * Constructs a circle of radius aRadius
        * @param aRadius is the radius of the circle
        */
        public void draw(double aRadius, Color color)
        {
             radius = aRadius; // assigns value to radius
             circumference = ( 2 * pi * radius); // arithmetic for circumference
             area = ( pi * radius * radius); // arithmetic for area
             color = color; // displays type of color

         }

         public void draw (Graphics2D circle)
         {
         circle.setColor (color);
         }

        /**
        */
        public double getRadius()
        {
            return radius;
        }

        public double getCircumference()
        {
            return circumference;
        }

        public double getArea()
        {
            return area;
        }

        public Color getColor()
        {
            return color;
        }
    }

这是我的第二堂课,我有'.class'预期错误。我相信这是我有新圆(双半径,颜色)的地方

    import java.util.Scanner;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.geom.Ellipse2D;


    /**
    * Main method for circle class.
    * 
    * @author Kelvynn Cayanan 
    * @version 02/09/2014
    */
    public class Driver
    {
         public static void main(String[] args)
        {


            Scanner keyboard = new Scanner(System.in);

            double circumference;
            double radius = 5.5;
            double pi = 3.1415926;
            double area = 0;
            Color color;

            Circle circle = new Circle(double radius,color);
            Ellipse2D.Double circle = new Ellipse2D.Double();

    circle.circumerence = 2*radius;
    cirlce.area = pi * (radius * 2);
    circle.x = (double) 10;
    circle.y = (double) 10;
    circle.draw(circle);
    cirlce.setColor(Color.Blue); // setting fill color
    cirlce.fill(circle);
    //Get Radius
    System.out.println("Circle's Radius");
    radius = keyboard.nextDouble();

    System.out.println("New Circle Object");

    Circle circle = new Circle();

    System.out.println("Area of Circle: " + Circle.getArea());
    System.out.println("Circumference of Circle: " + Circle.getCircumference());

}

}

为了编译它,我需​​要添加什么?

2 个答案:

答案 0 :(得分:4)

Circle circle = new Circle(double radius,color);
                             ^
                             |
                         syntax error

应该是:

Circle circle = new Circle(radius, color);

答案 1 :(得分:0)

在参数中取出'double'以在Driver类中创建一个新的Circle对象 - 这是一个语法错误。