找不到符号 - 符号 class 日期 - 位置包 java.util
cannot find symbol - symbol class date - Location package java.util
我找不到我的错误。程序说无法找到 class 日期。请帮我找出错误。
它是一种继承和多态class。
我有 classes:GeometricObject、Circle 和 Rectangle classes。
在 GeometricObject class 中,我在私有 java.util.Date dateCreated 中出错。在所有通知错误的程序中,日期都被标记为红色。不知道怎么解决。
package geometricobject;
import java.util.Date;
/**
*
* @author kharm
*/
public class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
public GeometricObject(){
dateCreated = new Java.util.Date();
}
/** COnstruct a geometric object with the specific color and filled value */
public GeometricObject(String color, boolean filled){
dateCreated= new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Return color */
public String getColor(){
return color;
}
/** Set a new color */
public void setColor(String color){
this.color = color;
}
/** Return filled. Since filled is boolean
its getter method is named isFilled */
public boolean isFilled(){
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled){
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated(){
return dateCreated;
}
/** Return a string representation of this object */
public String toString(){
return "created on" + dateCreated + "\ncolor: " + color + " and filled: " + filled;
}
package geometricobject;
/**
*
* @author kharm
*/
public class Circle extends GeometricObject {
private double radius;
public Circle(){
}
public Circle(double radius){
this.radius = radius;
}
public Circle(double radius, String color, boolean filled){
this.radius = radius;
setColor(color);
setFilled(filled);
}
/** Return radius
* @param <error>
* @return */
public double getRadius(){
return radius;
}
/** Set a new radius*/
public void setRadius(double radius){
this.radius = radius;
}
/** return area*/
public double getArea(){
return radius * radius * Math.PI;
}
/** Return diameter*/
public double getDiameter(){
return 2 * radius;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * radius * Math.PI;
}
/** Print the Circle info */
public void printCircle(){
System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius);
}
}
package geometricobject;
/**
*
* @author kharm
*/
public class Rectangle extends GeometricObject{
private double width;
private double height;
public Rectangle(){
}
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public Rectangle(double width, double height, String color, boolean filled){
this.width = width;
this.height = height;
setColor(color);
setFilled(filled);
}
/** Return width */
public double getWidth(){
return width;
}
/** Set a new width*/
public void setWidth(double width){
this.width = width;
}
/** Return height*/
public double gerHeight(){
return height;
}
/** Set a new height*/
public void setHeight(double height){
this.height = height;
}
/** Return area*/
public double getArea(){
return width * height;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * (width + height);
}
}
package geometricobject;
public class TestCircleRectangle{
public static void main(String[] args) {
Circle circle = new Circle(1);
System.out.println("A Circle " + circle.toString());
System.out.println("The color is " + circle.getColor());
System.out.println("The radius is " + circle.getRadius());
System.out.println("The area is " + circle.getArea());
System.out.println("The diameter is " + circle.getDiameter());
Rectangle rectangle = new Rectangle(2, 4);
System.out.println("/nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " + rectangle.getPerimeter());
}
}
导入日期后无需使用完整路径。
java.util.Date dateCreated; --> Date dateCreated;
将所有java.util.Date更改为日期
我也注意到你用大写写了一些 'J' :/
// The problem was that I wrote java.util.Date with UpperCaseLetter "Java". Thus,
// please check the spelling.
包几何对象;
导入 java.util.Date;
public class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
public GeometricObject(){
dateCreated = new java.util.Date();
}
/** Construct a geometric object with the specific color and filled value */
public GeometricObject(String color, boolean filled){
dateCreated= new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Return color */
public String getColor(){
return color;
}
/** Set a new color */
public void setColor(String color){
this.color = color;
}
/** Return filled. Since filled is boolean
its getter method is named isFilled */
public boolean isFilled(){
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled){
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated(){
return dateCreated;
}
/** Return a string representation of this object */
public String toString(){
return "created on" + dateCreated + "\ncolor: " + color + " and filled: " + filled;
}
package geometricobject;
public class Circle extends GeometricObject {
private double radius;
public Circle(){
}
public Circle(double radius){
this.radius = radius;
}
public Circle(double radius, String color, boolean filled){
this.radius = radius;
setColor(color);
setFilled(filled);
}
/** Return radius
* @param <error>
* @return */
public double getRadius(){
return radius;
}
/** Set a new radius*/
public void setRadius(double radius){
this.radius = radius;
}
/** return area*/
public double getArea(){
return radius * radius * Math.PI;
}
/** Return diameter*/
public double getDiameter(){
return 2 * radius;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * radius * Math.PI;
}
/** Print the Circle info */
public void printCircle(){
System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius);
}
}
package geometricobject;
/**
*
* @author kharm
*/
public class Rectangle extends GeometricObject{
private double width;
private double height;
public Rectangle(){
}
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public Rectangle(double width, double height, String color, boolean filled){
this.width = width;
this.height = height;
setColor(color);
setFilled(filled);
}
/** Return width */
public double getWidth(){
return width;
}
/** Set a new width*/
public void setWidth(double width){
this.width = width;
}
/** Return height*/
public double gerHeight(){
return height;
}
/** Set a new height*/
public void setHeight(double height){
this.height = height;
}
/** Return area*/
public double getArea(){
return width * height;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * (width + height);
}
}
package geometricobject;
public class TestCircleRectangle{
public static void main(String[] args) {
Circle circle = new Circle(1);
System.out.println("A Circle " + circle.toString());
System.out.println("The color is " + circle.getColor());
System.out.println("The radius is " + circle.getRadius());
System.out.println("The area is " + circle.getArea());
System.out.println("The diameter is " + circle.getDiameter());
Rectangle rectangle = new Rectangle(2, 4);
System.out.println("/nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " + rectangle.getPerimeter());
}
}
//输出正确:
运行:
A Circle 创建于 2 月 20 日星期六 13:35:28 CST 2021
颜色:白色,填充:false
颜色是白色
半径为 1.0
面积为 3.141592653589793
直径为2.0
2 月 20 日星期六创建的矩形 13:35:28 CST 2021
颜色:白色,填充:false
面积8.0
周长是12.0
我找不到我的错误。程序说无法找到 class 日期。请帮我找出错误。 它是一种继承和多态class。 我有 classes:GeometricObject、Circle 和 Rectangle classes。 在 GeometricObject class 中,我在私有 java.util.Date dateCreated 中出错。在所有通知错误的程序中,日期都被标记为红色。不知道怎么解决。
package geometricobject;
import java.util.Date;
/**
*
* @author kharm
*/
public class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
public GeometricObject(){
dateCreated = new Java.util.Date();
}
/** COnstruct a geometric object with the specific color and filled value */
public GeometricObject(String color, boolean filled){
dateCreated= new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Return color */
public String getColor(){
return color;
}
/** Set a new color */
public void setColor(String color){
this.color = color;
}
/** Return filled. Since filled is boolean
its getter method is named isFilled */
public boolean isFilled(){
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled){
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated(){
return dateCreated;
}
/** Return a string representation of this object */
public String toString(){
return "created on" + dateCreated + "\ncolor: " + color + " and filled: " + filled;
}
package geometricobject;
/**
*
* @author kharm
*/
public class Circle extends GeometricObject {
private double radius;
public Circle(){
}
public Circle(double radius){
this.radius = radius;
}
public Circle(double radius, String color, boolean filled){
this.radius = radius;
setColor(color);
setFilled(filled);
}
/** Return radius
* @param <error>
* @return */
public double getRadius(){
return radius;
}
/** Set a new radius*/
public void setRadius(double radius){
this.radius = radius;
}
/** return area*/
public double getArea(){
return radius * radius * Math.PI;
}
/** Return diameter*/
public double getDiameter(){
return 2 * radius;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * radius * Math.PI;
}
/** Print the Circle info */
public void printCircle(){
System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius);
}
}
package geometricobject;
/**
*
* @author kharm
*/
public class Rectangle extends GeometricObject{
private double width;
private double height;
public Rectangle(){
}
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public Rectangle(double width, double height, String color, boolean filled){
this.width = width;
this.height = height;
setColor(color);
setFilled(filled);
}
/** Return width */
public double getWidth(){
return width;
}
/** Set a new width*/
public void setWidth(double width){
this.width = width;
}
/** Return height*/
public double gerHeight(){
return height;
}
/** Set a new height*/
public void setHeight(double height){
this.height = height;
}
/** Return area*/
public double getArea(){
return width * height;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * (width + height);
}
}
package geometricobject;
public class TestCircleRectangle{
public static void main(String[] args) {
Circle circle = new Circle(1);
System.out.println("A Circle " + circle.toString());
System.out.println("The color is " + circle.getColor());
System.out.println("The radius is " + circle.getRadius());
System.out.println("The area is " + circle.getArea());
System.out.println("The diameter is " + circle.getDiameter());
Rectangle rectangle = new Rectangle(2, 4);
System.out.println("/nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " + rectangle.getPerimeter());
}
}
导入日期后无需使用完整路径。
java.util.Date dateCreated; --> Date dateCreated;
将所有java.util.Date更改为日期
我也注意到你用大写写了一些 'J' :/
// The problem was that I wrote java.util.Date with UpperCaseLetter "Java". Thus,
// please check the spelling.
包几何对象; 导入 java.util.Date;
public class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
public GeometricObject(){
dateCreated = new java.util.Date();
}
/** Construct a geometric object with the specific color and filled value */
public GeometricObject(String color, boolean filled){
dateCreated= new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Return color */
public String getColor(){
return color;
}
/** Set a new color */
public void setColor(String color){
this.color = color;
}
/** Return filled. Since filled is boolean
its getter method is named isFilled */
public boolean isFilled(){
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled){
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated(){
return dateCreated;
}
/** Return a string representation of this object */
public String toString(){
return "created on" + dateCreated + "\ncolor: " + color + " and filled: " + filled;
}
package geometricobject;
public class Circle extends GeometricObject {
private double radius;
public Circle(){
}
public Circle(double radius){
this.radius = radius;
}
public Circle(double radius, String color, boolean filled){
this.radius = radius;
setColor(color);
setFilled(filled);
}
/** Return radius
* @param <error>
* @return */
public double getRadius(){
return radius;
}
/** Set a new radius*/
public void setRadius(double radius){
this.radius = radius;
}
/** return area*/
public double getArea(){
return radius * radius * Math.PI;
}
/** Return diameter*/
public double getDiameter(){
return 2 * radius;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * radius * Math.PI;
}
/** Print the Circle info */
public void printCircle(){
System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius);
}
}
package geometricobject;
/**
*
* @author kharm
*/
public class Rectangle extends GeometricObject{
private double width;
private double height;
public Rectangle(){
}
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public Rectangle(double width, double height, String color, boolean filled){
this.width = width;
this.height = height;
setColor(color);
setFilled(filled);
}
/** Return width */
public double getWidth(){
return width;
}
/** Set a new width*/
public void setWidth(double width){
this.width = width;
}
/** Return height*/
public double gerHeight(){
return height;
}
/** Set a new height*/
public void setHeight(double height){
this.height = height;
}
/** Return area*/
public double getArea(){
return width * height;
}
/** Return perimeter*/
public double getPerimeter(){
return 2 * (width + height);
}
}
package geometricobject;
public class TestCircleRectangle{
public static void main(String[] args) {
Circle circle = new Circle(1);
System.out.println("A Circle " + circle.toString());
System.out.println("The color is " + circle.getColor());
System.out.println("The radius is " + circle.getRadius());
System.out.println("The area is " + circle.getArea());
System.out.println("The diameter is " + circle.getDiameter());
Rectangle rectangle = new Rectangle(2, 4);
System.out.println("/nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " + rectangle.getPerimeter());
}
}
//输出正确: 运行: A Circle 创建于 2 月 20 日星期六 13:35:28 CST 2021 颜色:白色,填充:false 颜色是白色 半径为 1.0 面积为 3.141592653589793 直径为2.0
2 月 20 日星期六创建的矩形 13:35:28 CST 2021 颜色:白色,填充:false 面积8.0 周长是12.0