[java]代码库
import java.util.*;
public class ShangPin { //商品类
private String Snum;
private String Sname;
private Date data;
private String CJname;
public ShangPin(){
Snum="";
Sname="";
CJname="";
}
@SuppressWarnings("deprecation")
public ShangPin(String Snum,String Sname,String CJname,int year,int month,int day){
this.Snum=new String(Snum);
this.Sname=new String(Sname);
this.CJname=new String(CJname);
this.data=new Date(year-1900,month-1,day);
}
public void setSnum(String Snum){this.Snum=Snum;}
public void setSname(String Sname){this.Sname=Sname;}
public void setCJname(String CJname){this.CJname=CJname;}
@SuppressWarnings("deprecation")
public void setdata(int year,int month,int day){
this.data=new Date(year-1900,month-1,day);
}
public String getSnum(){return Snum;}
public String getSname(){return Sname;}
public String getCJname(){return CJname;}
public Date data(){return data;}
public String toString(){
return "Snum:"+Snum+"\nSname:"+Sname+"\nChuChangday:"+String.format("%tF",data)+"\nCJname:"+CJname;
}
}
public class ShiPin extends ShangPin{ //食品类
private int BaoZhiQi;
private String changfen;
public ShiPin(){
super();
BaoZhiQi=0;
changfen="";
}
public ShiPin(String Snum,String Sname,String CJname,int year,int month,int day,int BaoZhiQi,String changfen){
super(Snum,Sname,CJname,year,month,day);
this.BaoZhiQi=BaoZhiQi;
this.changfen=new String(changfen);
}
public void setBaoZhiQi(int BaoZhiQi){this.BaoZhiQi=BaoZhiQi;}
public void setchengfen(String changfen){this.changfen=changfen;}
public int getBaoZhiQi(){return BaoZhiQi;}
public String getchangfen(){return changfen;}
public String toString(){
return "食品:"+super.toString()+"\nBaoZhiQi:"+BaoZhiQi+"天"+"\nchangfen:"+changfen+"\n\n";
}
}
public class FuZhuang extends ShangPin{
String XingHao;
String MianLiao;
public FuZhuang(){
super();
XingHao="";
MianLiao="";
}
public FuZhuang(String Snum,String Sname,String CJname,int year,int month,int day,String XingHao,String MianLiao){
super(Snum,Sname,CJname,year,month,day);
this.XingHao=new String(XingHao);
this.MianLiao=new String(MianLiao);
}
public void setXingHao(String XingHao){this.XingHao=XingHao;}
public void setMianLiao(String MianLiao){this.MianLiao=MianLiao;}
public String getXingHao(){return XingHao;}
public String getMianLiao(){return MianLiao;}
public String toString(){
return "服装:"+super.toString()+"\nXingHao:"+XingHao+"\nMianLiao:"+MianLiao+"\n\n";
}
}
public class TestShangPin {
public static void main(String[] args) {
// TODO 自动生成的方法存根
ShangPin []sp=new ShangPin[2];
sp[0]=new ShiPin("0001","面包","肯德基",2014,10,20,2,"面粉、鸡肉");
sp[1]=new FuZhuang("1001","T恤","凡客",2014,9,10,"XL","纯棉");
System.out.print(sp[0]);
System.out.print(sp[1]);
}
}