gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:35:56 25 4
gpt4 key购买 nike

我收到一个错误,指出我的第二个类(即驱动程序类)中预期有“.class”。

    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());

}

}

我必须添加什么才能编译?

最佳答案

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

应该是:

Circle circle = new Circle(radius, color);

关于java - .class 预期,我需要添加什么才能编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22023839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com