I'm working on a Java exercise and can't figure out what I am doing wrong. I made a Movie class (with variables: rating, title, movieId and a constant for FEE_AMT) and then extended the class with: Action, Comedy and Drama. These derived classes have no other variables, just a different FEE_AMT.
In Movie (and derived classes) there is a method to calculate the late fees due:
/**
* Returns the late fee due on a Movie rental
* @param days the number of days for late fee calculations
* @return true or false depending on the evaluation of the expression
**/
public double calcLateFees(int days){
return(days * FEE_AMT);
}
If I just call the method outright with the object, for ex: comedy1.calcLateFees(2)
- it will generate the correct fee amount based on the differing constant value in the derived method.
Now I needed to create a Rental
class and in main()
create an array of type rental class to hold Rental objects (which consist of a Movie object, renterId and daysLate).
Here is the method that takes in an array of Rental objects and returns the late fees due on all rentals in the array:
/**
* lateFeesOwed returns the amount of money due for late fees on all movies
* which are located in an array of Rentals.
*
* @return feeDue the amount of money due for late fees.
*/
public static double lateFeesOwed(Rental[] rentalArray){
double feeDue = 0;
for(int i = 0; i < rentalArray.length; i++)
{
feeDue += rentalArray[i].calcFees(); //This is part of the problem??
}
return feeDue;
}
and this method calls:
/**
* CalcFees returns the amount of money due for late fees on a movie rental.
*
* @return feeDue the amount of money due for late fees.
*/
public double calcFees(){
double feeDue = rentalName.calcLateFees(this.daysLate);
return feeDue;
}
But the problem is that the calcFees()
method is calling calcLateFees()
but instead of calling the derived class, it is calling the Movie class and returning the incorrect amount.
I'm not sure where my issue is preventing the overridden method calcLateFees()
from being called.
Thank you.