Reputation: 1
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 will 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.
Upvotes: 0
Views: 689
Reputation: 761
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);
}
}
Upvotes: 0
Reputation: 129564
Favor composition over inheritance. Try having a genre property in the movie class. The genre class can hold a fee member.
Upvotes: 0
Reputation: 26418
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);
}
Upvotes: 1
Reputation: 240900
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
Upvotes: 0