好的。我被困在我作业的这一部分。我需要将一个名为 getDisplayText 的抽象方法添加到产品类(下面给出的代码)。请告诉我放在哪里以及如何放置。你真是太好了。此外,此方法不应接受任何参数,并且应返回一个字符串对象。然后编译这个类。(对不起,我的英语不好...... - 这是什么意思?!保存文件?!)
这是代码:
import java.text.NumberFormat;
public abstract class Product {
private String code;
private String description;
private double price;
public static int count = 0;
public Product() {
code = "";
description = "";
price = 0;
}
public void setCode(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public void setPrice(double price) {
this.price = price;
}
public double getPrice() {
return price;
}
public String getFormattedPrice() {
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(price);
}
@Override
public String toString() {
return "Code: " + code + "\n" + "Description: " + description + "\n" + "Price: "
+ this.getFormattedPrice() + "\n";
}
public static int getCount() {
return count;
}
}