| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 999 人关注过本帖
标题:vector---未经检查或是不安全的操作!
只看楼主 加入收藏
任永旺
Rank: 1
来 自:河南项城
等 级:新手上路
帖 子:9
专家分:2
注 册:2010-4-16
收藏
 问题点数:0 回复次数:1 
vector---未经检查或是不安全的操作!
程序本身已经能运行了,可是搞不懂怎样才能在去掉程序中红色部分@SuppressWarnings({ "serial", "unchecked" })也能让程序继续运行?谢谢!!!!!
import java.util.*;

class CD{
    String id;
    float price;
    String name;
    String company;
   
    CD(String id,float price,String name,String company){
        this.id=id;
        this.price=price;
        this.name=name;
        
        }
    }
   
 @SuppressWarnings({ "serial", "unchecked" })
public class CDMessage extends Vector{
        public static Scanner scanner=new Scanner(System.in);
Vector myVector;
    public  void  createCDMessage(){
        myVector=new Vector(50,1);
        String name,id,company;
      float price;
        boolean N=true;
        while(N){
            System.out.println("id");
            try{
            id=scanner.next();
        }catch(Exception e){
            System.out.println("you are wrong");
            id="nul";
            }
            System.out.println("price");
                try{
            price=scanner.nextFloat();
        }catch(Exception e){
            System.out.println("you are wrong");
            price=0;
            }

            System.out.println("name");
                        try{
        name=scanner.next();
        }catch(Exception e){
            System.out.println("you are wrong");
            name="nul";
            }
   
            System.out.println("company");
                                    try{
                company=scanner.next();
        }catch(Exception e){
            System.out.println("you are wrong");
            company="nul";
            }

            CD cd=new CD(id,price,name,company);
            System.out.println(cd.name);
            myVector.addElement(cd);
            System.out.println("1continue   \n   else break:\nplease enter your choice");
            int i=scanner.nextInt();
            if(i!=1)
            N=false;
            }         
        }
        
        
        public void findByName(){
            int m=0;
            String name;
            System.out.println("qing shuru CD name");
            try{
              name=scanner.next();
        }catch(Exception e){
            System.out.println("you are wrong");
            name="nul";
            }
         for(m=0;m<myVector.size();m++)
         {
         CD cd=(CD)myVector.elementAt(m);
         if(((cd.name).trim()).compareTo(name.trim())==0){
         System.out.println("name "+cd.name+"     id     "+cd.id+"    company    "+   price     "+cd.price);
        break;
       }
       }
       System.out.println("do not find the message");
            }
            
            public void deletedByName(){
                String name;
                int m;
            System.out.println("qing shuru the deleted CD name");
            try{
          name=scanner.next();
           }catch(Exception e){
            System.out.println("you are wrong");
            name="nul";
            }
         for(m=0;m<myVector.size();m++)
         {
         CD cd=(CD)myVector.elementAt(m);
         if(((cd.name).trim()).compareTo(name.trim())==0){
         System.out.println("the deleleted cd message\nname "+cd.name+"     id     "+cd.id+"    company    "+   price     "+cd.price);
         myVector.removeElementAt(m);
         break;
       }
       }
                }
        
    public static void main(String[] args){
        CDMessage myCdMessage=new CDMessage();
      myCdMessage.createCDMessage();
      myCdMessage.findByName();
      myCdMessage.deletedByName();
      myCdMessage.findByName();
        }
    }


[ 本帖最后由 任永旺 于 2010-7-18 12:25 编辑 ]
搜索更多相关主题的帖子: 检查 vector 
2010-07-17 10:06
cixi2010
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2009-2-16
收藏
得分:0 
厉害的你们
2010-09-09 17:19
快速回复:vector---未经检查或是不安全的操作!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.110277 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved