课程编号:
面向对象程序设计
实验报告
实验1
一.实验目的:
加强我自己使用继承来实现Java类的能力
二.实验内容:
1.首先根据要求实现超类Product类。以利于以后商品Coffee类,
CoffeeBrewer类,Orderitem类的继承。
2.根据要求实现Coffee类,CoffeeBrewer类,Orderitem类。
3.实现如下类图:
4.
三.实验步骤:
1.首先根据要求设计出一下的类图。
5.不同的类的具体要求如下(都要继承超类Product类)。(1)C lass Product
a.含有的变量:
soil
code;
description;
price;
b.含有的方法:
.public Product(String code,String
description,double price)
public String getCode().返回实例变量的code.
∙public String getDescription().返回实例变量的variable description.
∙public double getPrice().返回实例变量的 price.
∙boolean equals(Object object). 重写方法 equals i在类Object里,如果他们的code是相等的,则产品对象是相等
的。
∙String toString(). 重写方法toString 在类Object里.
返回的格式如下:
∙code_description_price
c.写完具体如下:
publicclass Product {
private String code;
private String description;
privatedouble price;
public Product(String code,String description,double price) {
rangthis.description=description;
this.price=price;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
publicdouble getPrice() {
commend和recommend
return price;
}
瓶子的英文@Override
publicboolean equals(Object a) {
if (a instanceof Product) {
if (((Product) a).code==Code()) {
poorerreturntrue;
}
el {
returnfal;
}
}
returnfal;
韦博英语软件}
@Override
hip pocketpublic String toString() {
return (Code()+"_"+Description()+"_"+Price());
path finder>who is the cutest}
}
(2)c lass Coffee
a.含有的变量:
∙origin.
∙roast.
∙flavor.
∙aroma.
∙acidity.
the lumineers∙body.
b.含有的方法:
public Coffee(String code,String description,Double