需要添加jar:metadata-extractor-2.3.1.jar

Java代码 复制代码  收藏代码
  1. import java.util.Calendar;   
  2.  class Product {  //一般商品类   
  3.       String productName; //名称   
  4.       double price;  //价格   
  5.       String ID;    //编号   
  6.       String unit;  //单价   
  7.      
  8.     public Product(String ID,String productName,double price,String unit){  //父类构造函数   
  9.         this.ID = ID;   
  10.         this.productName = productName;   
  11.         this.price = price;   
  12.         this.unit = unit;   
  13.     }   
  14.     public String getProductName(){   
  15.         return this.productName;   
  16.     }   
  17.     public double getPrice(){   
  18.         return this.price;   
  19.     }   
  20.     public String getID(){   
  21.         return this.ID;   
  22.     }   
  23.     public String getUnit(){   
  24.         return this.unit;   
  25.     }   
  26.     public String toString(){   
  27.         return "商品ID为:"+this.ID+"\t商品名称为:"+this.productName+"价格:"+this.price+"单位:"+this.unit;   
  28.     }   
  29. }   
  30. public class DiscountedProduct11 extends Product{   
  31.      private Calendar startDate;   
  32.      private Calendar endDate;   
  33.      private double discount;  //折扣   
  34.      public DiscountedProduct11(String ID,String productName,double price,String unit,   
  35.              Calendar startDate,Calendar endDate,double discount){               //子类构造函数   
  36.          super(ID,productName,price,unit);                   //****************************   
  37.          this.startDate = startDate;   
  38.          this.endDate = endDate;   
  39.          this.discount = discount;   
  40.      }   
  41.      public Calendar getStartDate(){   
  42.          return this.startDate;   
  43.      }    
  44.      public Calendar getEndDate(){   
  45.          return this.endDate;   
  46.      }   
  47.      public double getDiscount(){   
  48.          return this.discount;   
  49.      }   
  50.      public String toString(){   
  51.             return "商品ID为:"+this.ID+"\n商品名称为:"+this.productName+"\n价格:"+this.price+"\n单位:"+this.unit+   
  52.                     "\n开始时间为:"+this.startDate.getTime()+"\n结束时间为:"+this.endDate.getTime()+"\n折扣率为:"+this.discount;   
  53.         }   
  54.         
  55.      public static void main(String args[]){   
  56.             
  57.          System.out.println("当前时间为:");   
  58.          Calendar cal = Calendar.getInstance();   
  59.          System.out.println(cal.getTime());   //获得当前时间   
  60.             
  61.          Calendar cal2=Calendar.getInstance();   
  62.          cal2.set(Calendar.MONDAY, 10);      //修改时间属性   
  63.             
  64.          System.out.println("*****************************************");   
  65.          DiscountedProduct11 DP = new DiscountedProduct11("001","苹果",2.0,"/kg",cal,cal2,0.2);   
  66.          System.out.println(DP);   
  67.             
  68.          System.out.println("*****************************************");   
  69.          Product p = new DiscountedProduct11("002","香蕉",3.0,"/kg",cal,cal2,0.3);  //upcasting   
  70.          System.out.println(p);   
  71.             
  72.      }   
  73.  }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值