Given four shapes a,b,c,d:
a "0 0 0 1 1 1 1 0"
b "10 10 10 11 11 11 11 10"
c "0.5 0.5 0.5 -10 1.5 0"
d "0.5 0.5 0.75 0.75 0.75 0.2"
我要请教的是:如何用Java语言声明shape类及其四个对象a,b,c,d。注意:a中内容是4个point(点)(0,0)(0,1)(1,1)(1,0).b,c,d也是一样。

解决方案 »

  1.   

    API中没有就只能自己写方法传参数了
      

  2.   


    Class Shape
    {
       double[] points = new double[8];
       public Shape(String pointsString)
       {
         ....... //String array to number array
       }
    }Shape a = new Shape(strA);
      

  3.   


      public static void main(String[] args)
        {
            String a = "0 0 0 1 1 1 1 0";
            shape(a);
        }    private static void shape(String a)
        {
            String[] strings = a.split(" ");
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < strings.length; i++)
            {
                String string = strings[i];            if ((i + 1) % 2 == 0)
                {
                    sb.append(string);
                    System.out.println(sb);
                    sb = new StringBuffer();            } else
                {
                    sb.append(string);
                    sb.append(",");
                }
            }
        }
      

  4.   

    虽然结贴了还是可以回复,如果你按照4楼的写OO程序,你将....不是在class里面就是面向对象的。