java我不懂,同学的作业,没办法

解决方案 »

  1.   

    不过给你个参考:
    //: c07:Shapes.java
    // From 'Thinking in Java, 2nd ed.' by Bruce Eckel
    // www.BruceEckel.com. See copyright notice in CopyRight.txt.
    // Polymorphism in Java.class Shape { 
      void draw() {}
      void erase() {} 
    }class Circle extends Shape {
      void draw() { 
        System.out.println("Circle.draw()"); 
      }
      void erase() { 
        System.out.println("Circle.erase()"); 
      }
    }class Square extends Shape {
      void draw() { 
        System.out.println("Square.draw()"); 
      }
      void erase() { 
        System.out.println("Square.erase()"); 
      }
    }class Triangle extends Shape {
      void draw() { 
        System.out.println("Triangle.draw()"); 
      }
      void erase() { 
        System.out.println("Triangle.erase()");
      }
    }public class Shapes {
      public static Shape randShape() {
        switch((int)(Math.random() * 3)) {
          default:
          case 0: return new Circle();
          case 1: return new Square();
          case 2: return new Triangle();
        }
      }
      public static void main(String[] args) {
        Shape[] s = new Shape[9];
        // Fill up the array with shapes:
        for(int i = 0; i < s.length; i++)
          s[i] = randShape();
        // Make polymorphic method calls:
        for(int i = 0; i < s.length; i++)
          s[i].draw();
      }
    } ///:~
      

  2.   

    给你个建议
    随便找一本java书去抄一下
    不过说实在的
    您这问题确实简单了点
    但是要是一行一行的编
    有点郁闷