高人帮小妹看看这几个java程序,急急急!!满意绝对追加分

2024-12-15 00:48:42
推荐回答(3个)
回答1:

import java.util.Date;

/**
* 试定义一个商品类,然后在此基础上在定义一个食品类,一个服装子类。
* 假设任何商品都应该有商品编号、商品名称、出厂日期、产品厂家名称等信息;
* 除此之外,食品还应该包含保质期、主要成分等信息,
* 服装品还应该包含型号、面料等信息。
* */

public class Goods {

private int id;
private String name;
private Date date;
private String factory;

public Goods(int id, String name, Date date, String factory) {
super();
this.id = id;
this.name = name;
this.date = date;
this.factory = factory;
}

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getFactory() {
return factory;
}
public void setFactory(String factory) {
this.factory = factory;
}

@Override
public String toString() {
return "Goods [date=" + date + ", factory=" + factory + ", id=" + id
+ ", name=" + name + "]";
}
}

class Food extends Goods{

private Date dateKeep; //保质期
private String main; //主要成分

public Food(int id, String name, Date date, String factory, Date dateKeep,
String main) {
super(id, name, date, factory);
this.dateKeep = dateKeep;
this.main = main;
}

public Date getDateKeep() {
return dateKeep;
}

public void setDateKeep(Date dateKeep) {
this.dateKeep = dateKeep;
}

public String getMain() {
return main;
}

public void setMain(String main) {
this.main = main;
}

}

class Clothing extends Goods{

private int type; //型号
private String fabric;//面料

public Clothing(int id, String name, Date date, String factory, int type,
String fabric) {
super(id, name, date, factory);
this.type = type;
this.fabric = fabric;
}

public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getFabric() {
return fabric;
}
public void setFabric(String fabric) {
this.fabric = fabric;
}

}
http://zhidao.baidu.com/question/161264005.html

回答2:

作业复制同学的就可以了

回答3:

public interface 商品{
public 商品编号();
public 商品名称();
public 出场日期();
public 厂家名称();
}
class 食品 implements 商品{
/*实现抽象方法*/
public 商品编号(){}
public 商品名称(){}
public 出场日期(){}
public 厂家名称(){}
/*自己特有的方法*/
public 保质期(){}
public 主要成分(){}
}
class 服装 implements 商品{
/*实现抽象方法*/
public 商品编号(){}
public 商品名称(){}
public 出场日期(){}
public 厂家名称(){}
public 型号(){}
public 面料(){}
}
不知您觉得对否