-3

我的对象如下所示: 请注意,这不是家庭作业,而是我自己做的一个网络项目。所以帮助将不胜感激!

enum size { small, big; }

Class Controller
{
    size sizeType;
}

Class square extends shape
{
    int num = 1;
}

Class circle extends shape
{
  int num=2;
  size size = size.Small;
}

void method()
{
    Controller[] sizes = new Controller[n];
    // e.g. shape = {small, big, small, small, big}

    Shape circle = new Shape();
    /* Find 2 'small' continuous circles 
       OR find 'size' based on the num value 
       (circle has 2 but should be able to accept 
       any integer = num declared in the shape class */

    // RETURN occurrence of first such index for e.g. 2 as found in 2,3    
}
4

1 回答 1

1

您的代码的真正问题是:您完全破坏了对象层次结构。

首先,根据我对您的意图的猜测,这里有一些小的更正:

enum SizeType { SMALL, BIG; }

class Shape {
    SizeType size;
}

class Square extends Shape {
    int num = 1;
}

class Circle extends Shape {
    int num = 2;
    SizeType size = SizeType.SMALL;
}

int findShapeSequence(Shape[] shapes) {
    // TODO find the first instance of a repeated size value in the array,
    // and return the index of the first of the shapes whose size repeats.   
}

既然这已经被清除了,那么您应该很容易弄清楚如何实际执行您希望您的方法执行的操作。

于 2013-06-24T20:25:16.787 回答