• 140201126杨鹏飞作业七


    interface Yongpin{ 
     public String getName();
     public int getCount1();
     public float getPrice();
    }
    class Wenju implements Yongpin{ 
     private String name ; 
     private int count1 ;
     private float price;
     public Wenju(String name,int count1,float price){
      this.setName(name);
      this.setCount1(count1);
      this.setPrice(price);
     }
     public void setName(String name){
      this.name = name ;
     }
     public void setCount1(int count1){
      this.count1 = count1 ;
     }
     public void setPrice(float price){
      this.price=price;
     }
     public String getName(){
      return this.name ;
     }
     public int getCount1(){
      return this.count1 ;
     }
     public float getPrice(){
      return price;
     }
    };
    class Shenghuoyongpin implements Yongpin{ 
     private String name; 
     private int count1;
     private float price;
     public Shenghuoyongpin(String name,int count1,float price){
      this.setName(name);
      this.setCount1(count1);
      this.setPrice(price);
     }
     public void setName(String name){
      this.name = name ;
     }
     public void setCount1(int count1){
      this.count1=count1;
     }
     public void setPrice(float price){
      this.price=price;
     }
     public String getName(){
      return this.name;
     }
     public int getCount1(){
      return this.count1 ;
     }
     public float getPrice(){
      return price;
     }
    };
    class Gouwuche{ 
     private Yongpin[] yongpins ; 
     private int foot ;
     public Gouwuche(int len){
      if(len>0){
       this.yongpins= new Yongpin[len] ; 
      }else{
       this.yongpins = new Yongpin[1] ; 
      }
     }
     public boolean add(Yongpin yongpin){ 
      if(this.foot<this.yongpins.length){
       this.yongpins[this.foot] = yongpin ; 
       this.foot++ ;
       return true ;
      }else{
       return false ;
      }
     }
     public Yongpin[] search(String keyWord){
      Yongpin y[] = null ;
      int count = 0 ; 
      for(int i=0;i<this.yongpins.length;i++){
       if(this.yongpins[i]!=null){  
        if(this.yongpins[i].getName().indexOf(keyWord)!=-1){
         count++ ; 
        }
       }
      }
      y = new Yongpin[count] ; 
      int f = 0 ; 
      for(int i=0;i<this.yongpins.length;i++){
       if(this.yongpins[i]!=null){  
        if(this.yongpins[i].getName().indexOf(keyWord)!=-1){
         y[f] = this.yongpins[i];
         f++ ;
        }
       }
      }
      return y ;
     }
    };
    public class ADemo6 {
     public static void main(String[] args) {
      Gouwuche g=new Gouwuche(6);
      g.add(new Wenju("单肩包",1,130.5f));
      g.add(new Wenju("碳素笔",2,3.0f));
      g.add(new Wenju("参考资料",2,43.4f));
      g.add(new Shenghuoyongpin("脸盆",2,50.8f));
      g.add(new Shenghuoyongpin("洗手液",1,15.1f));
      g.add(new Shenghuoyongpin("脸霜",1,67.2f));
      print(g.search(""));
      
     }
     public static void print(Yongpin y[]){
      float sum=0;
      for(int i=0;i<y.length;i++){
       if(y[i]!=null){
        System.out.println(y[i].getName() + "," + y[i].getCount1()+","+y[i].getPrice());
       }
       sum=sum+y[i].getPrice();
      }
      System.out.println("sum:"+sum);
     }
    }

  • 相关阅读:
    常用的 写代码 的 指令
    boos
    超级搬运工
    那些年,我读过的书籍(读完一本就在此处更新),立贴。
    ExtJs combobox模糊匹配
    整理了一下eclipse 快捷键注释的一份文档
    中国省份按照拼音排序出现的问题以及临时解决方案
    JetBrains WebStorm 安装破解问题
    ExtJs Grid 删除,编辑,查看详细等超链接处理
    ExtJs Panel 滚动条设置
  • 原文地址:https://www.cnblogs.com/yangpengfei123/p/5444278.html
Copyright © 2020-2023  润新知