Невозможно определить тип Shape.Я уже изменил заголовок класса, чтобы расширить форму.Продолжайте получать ту же ошибку - PullRequest
0 голосов
/ 09 мая 2018

Я получаю сообщение об ошибке не могу создать экземпляр типа Shape. Я изменил заголовок класса на открытый класс ShapeDriver расширяет форму. Все та же ошибка. Мое назначение требует от меня написания кода наследования, который будет отображать 3 разные фигуры в консоли Eclipse. Я продолжаю получать эту ошибку в своем коде, когда я пытаюсь запустить его, но я не могу понять, что не так. Любые советы или рекомендации будут оценены.

ShapeDriver.java

package shape;
    import java.io.FileNotFoundException;
    import java.util.*;

    public class ShapeDriver extends Shape {
        public static void start() throws FileNotFoundException{

            Scanner input = new Scanner (System.in);
            String fileName;
            ArrayList<Shape> shapes;

            System.out.println("Enter a file name: ");
            fileName= input.next();

            shapes = create(fileName); // calls create that returns a list of shapes.
            display(shapes); // calls display to print the list of shapes in order.

            input.close();
        }

        private static ArrayList<Shape> create(String fileName) {

            return null;
        }

        private static void display(ArrayList<Shape> shapes) {

        }

        /**
         * Tests all methods in Shape design.
         * @param args A reference to a string array containing command-line
         * arguments
         */
        public static void main(String[] args){

            //Creates at least two shape objects.
            Shape shape1 = new Shape();
            Shape shape2 = new Shape();     

            //Retrieves the name of first shape, and store it in memory.
            System.out.println("Shape1: " + shape1.getName());

            //Print the name of the first shape.
            System.out.println("Shape1");

            //Changes the name of the first shape.
            shape1.setName("shape1.");


            //Retrieves the name of first shape again, store it in memory.
            System.out.println("Shape1: " + shape1.getName());

            //Print the name of the first shape again.
            System.out.println("Shape1");

            //Print first shape object.
            System.out.println(shape1);

            //Print other shape objects.
            System.out.println(shape2);

            //Compares the first shape with itself, print the results.
            System.out.println("Shape1 is equal to shape1: " + shape1.equals(shape1));
            //Compares the first shape with another shape, print the results.
            System.out.println("Shape1 is equal to shape2: " + shape1.equals(shape2));

            //Compares the first shape with a String object, print the result
            System.out.println("Shape1 is equal to string hello: " + shape1.equals(new String("Hello")) );
        }

        @Override
        public double area() {
            // TODO Auto-generated method stub
            return 0;
        }

    }

Shape.java

package shape;
import java.text.DecimalFormat;
public abstract class Shape {

// Declare variables
DecimalFormat shapeDecimalFormat = new DecimalFormat("0.00");

/**
 * The name of this shape
 */
private String name;

/***
 * Returns the area of this shape.
 * @return The area of this shape.
 */

public abstract double area();

/**
 *  Constructs a shape with default name.
 */

public Shape(){
        name = this.getClass().getName();

}

/**
 * Returns the name of this shape.
 * @param
 */

public Shape(String name){
        this.name = name;
}

/**
 * Returns the name of this shape.
 * 
 * @return A string specifying the name of this shape.
 */

public String getName(){
        return name;

} 

/**
 * Constructs a shape with a specific name.
 * @param name  The name of this shape
 */

public void setName(String name){
    this.name = name;

} 

/**
 * Indicates if this shape is "equal to" some other object. If the other object
 * is not a shape, return false. If the other object is a * shape, and has the
 * same name, return true.
 * 
 * @param obj An Object reference to a specific object
 * @return A boolean value specifying whether this shape is equal to some other
 *         object
 */

public boolean equals(Shape obj){
    if (obj.getName().compareToIgnoreCase(name) == 0)
        return true;
else
        return false;

}

/**
 * Returns a string representation of this shape containing the type * and
 * hidden values.
 * 
 * @return A string representation of this shape
 */

public String toString(){
    return "\n Shape: " + name + " Area = " + shapeDecimalFormat.format(area());

     } 

} 
...