本帖最后由 yhy115566957 于 2010-02-04 08:55:05 编辑

解决方案 »

  1.   

    是作业题,没人帮下吗
    现在的要求似乎还只是输出一条语句,用STING [],想问下,用HASHMAP容纳那些图形类吗
      

  2.   

    作业题的话就自己做,不要把在 CSDN 的人当作是免费的代码工!
      

  3.   

    设计一个图形列表类,列表能容纳的图形有园、三角、矩形等(日后可能还需要增加一些新的图形) 
    列表要支持:绘制、插入、删除、统计当前所容纳的各类图形的个数等功能。 目前各种图形的绘制只要用文本表示就可以,比如画园就打文本“我是一个园” 假如图形列表中有两个园,一个矩形,那么绘制效果类似下面: 1、我是一个园 
    2、我是一个园 
    3、我是一个矩形 (UI方面不需要设计,但要提供这个类的绘制,插入,删除,统计接口)接受大家的教导,  希望能帮我看看,基本的面向对象的思想达到了没.谢谢了 自己觉的自己的代码有点冗余Graphics_List文件:public abstract class Graphics_List {
    public  abstract  void print(int cod);
     public abstract void add();
       public  abstract void delete();
       public  abstract int getCount();
    }
    GraphicsListIn文件:  //简单工程方法,将图形列表类包含的图形可以 扩展
    public interface  GraphicsListIn{
       public   String  draw();
    }class   Round implements  GraphicsListIn{
        public String draw(){
       return  "我是一个园";
        }
    }class  Triangle implements  GraphicsListIn{
        public String draw()
       {
         return   "我是一个三角形";
       }
    }
    class  Rectangular implements  GraphicsListIn{

        public String draw()
       {
         return  "我是一个矩形";
       }
    }
    class  Drawer{
       public  static GraphicsListIn drawGraphics(String s) throws Exception{
            if(s.equalsIgnoreCase("Round"))
                  {
                  return  new Round();
                  }
             else if(s.equalsIgnoreCase("Triangle"))
                {
                     return  new Triangle();
                 }
              else if(s.equalsIgnoreCase("Rectangular"))
             {
                    return new Rectangular();
            }
            else  throw new Exception();
    }
    }GraphicsList1文件:
    import java.awt.Graphics;
        import java.util.ArrayList;   public class   GraphicsList1 extends Graphics_List  {
           
    static  ArrayList<String> parraylist ;

     static int num=0;
    static  ArrayList  arraylist;//这几个定义成静态的是因为如果不是静态的定义的方法里arraylist不知道怎么用.

           public static  void main(String [] args){
               try{
         GraphicsListIn  graphicsRou= Drawer.drawGraphics("Round");
        GraphicsListIn  graphicsT= Drawer.drawGraphics("Triangle");
         GraphicsListIn  graphicsRec= Drawer.drawGraphics("Rectangular");
                
                arraylist=new ArrayList();
                arraylist.add(0,graphicsRou.draw());
                arraylist.add(1,graphicsT.draw());
                arraylist.add(2,graphicsRec.draw());//图形列表里包含这三种图形,知道LIST是可以重复的,一时不知道用那个容器,明天这作业要交给老大看了,不知道TEY到这里的内容能不能剥离出去,我没试了没实现.
            
           GraphicsList1 glist=new GraphicsList1();
       
           parraylist =new ArrayList();
       
     //下面这几个是测试函数,这个PRINT是绘画的接口功能
           glist.print(1);
           glist.print(2);
           glist.print(3);
           glist.print(2);
           glist.print(1);
           glist.print(2);
           glist.print(3);
           System.out.println(num);
           glist.delete();
           System.out.println(num);
           glist.delete();
           
           System.out.println(num);
           glist.delete();
           System.out.println(num);
          }catch(Exception ex)
          { ex.printStackTrace();}      
          
       }
       public  void  print(int code) {
     try{  
        switch(code)
        { 
         
        case 1:
           
         System.out.println(Integer.toString(num+1) +"."+arraylist.get(0));
        
         parraylist.add(num,Drawer.drawGraphics("Round").draw());
         num++;
              
        
         break;
       case 2:
      System.out.println(Integer.toString(num+1) +"."+arraylist.get(1));
       parraylist.add(num,Drawer.drawGraphics("Triangle").draw());
        
         num++;
         break;
        case 3:
       System.out.println(Integer.toString(num+1) +"."+arraylist.get(2));
       parraylist.add(num,Drawer.drawGraphics("Rectangular").draw());
         num++;
         break;
        }
                   }catchJ(Exception ex)
                   {
                          ex.printStackTrace();
    }
       }
    //删除功能,只能删除最后一个,汗!!
    @Override
    public void delete() {
    if(num>=0){
    parraylist.remove(num-1);
    num--;
    }else
    {
    System.out.println("到最后 一个了");
    }

    }
    //静态变量统计数量
    @Override
    public int getCount() {

    return num;
    }
    }
      

  4.   

    你每一个空格的地方都是敲三个空格的?咋感觉像是老版 CSDN 的风格啊?老版的 CSDN 就喜欢把 1 个空格自说自话地替换为 3 个空格。