开发者

How to input this method for calculating cost

I am writing a class for a program where now I need to add a method for coming up with a late fee cost. This is between movie genre's with each genre costing something different but for the one I will use here wil开发者_StackOverflow社区l be the Drama genre which has the default late fee (That variable is in a different class, also the dayLate variable is in another class as well)

Anyway what I need to do is make it so that the method adds it up like the number of days late multiplied by the fee. Right now I have this but I get a compiler error (Also if it matters, the class with the dayLate variable is not yet finished or compiled)

Anyway here is the Drama class source code

class Drama extends Movie
{
    public Drama()
    {
        super();
    }
    public Drama(String rating, int IDnumber, String MovieTitle)
    {
        super(rating, IDnumber, MovieTitle);
    }
    public double CalcLateFees(Fee * dayLate);
}

I don't think I did this method correct though.


You cannot write your logic in the method's prototype, instead you should receive the values as the parameter and do the logic and return the values like below:

public double CalcLateFees(double fee, double dayLate) {

return (fee * dayLate);

}


Java doesn't use pointer just uses reference

So change this

public double CalcLateFees(Fee * dayLate);

to

public double CalcLateFees(Fee  dayLate);

Also make sure Movie class has default const and const with (String rating, int IDnumber, String MovieTitle) arguments


Favor composition over inheritance. Try having a genre property in the movie class. The genre class can hold a fee member.


switch (yourChoice) {

case 1: Implement your CalclateFees method some how:

public double CalcLateFees(Fee dayLate) {
   double fee = 0;
   ....
   return fee;
}

case 2: Declare your CalclateFees method as abstract:

public abstract double CalcLateFees(Fee  dayLate);

case 3: Let the Fee class handle the caculation:

public double CalcLateFees(Fee  dayLate) {
    return dayLate.calc(this);
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜