【发布时间】:2016-05-06 16:00:49
【问题描述】:
我还需要一个覆盖的 calclatefees 方法来计算过期电影的滞纳金。
public class Action extends Movie {
protected double latecost;
protected double latefees;
public Action (String title, String rating, int id, int rentTime,
double latecost, double latefees ) {
super(title, rating, id, rentTime);
this.title = title;
this.rating= rating;
this.id = id;
this.rentTime= 8;
this.latecost = 2;
System.out.println( "Overridden " + title + rating + " " + id + " "
+ latecost + " " + latefees);
}
public double calclatefees (double latecost) {
if (rentTime > 3)
latefees = ((rentTime - 3) * latecost);
return latefees;}
@Override
public String toString () {
String x = "Movie: " + title + " is rated " + rating + "\nMovie ID number:"
+ id + " late fees are $" + latefees;
return x;
}
}
【问题讨论】:
-
一些输出会有帮助。
-
抛开您遇到的问题,考虑将动作、喜剧和戏剧重构为枚举器,这是电影的更好属性,而不是继承的电影... :)
-
我想看看为什么我的 toString 没有发回我放在重载构造函数中的值,以及为什么当我在我的 super 中分配它们时它们仍然不会发回。
标签: java inheritance polymorphism