Created
April 20, 2013 02:08
-
-
Save csabatini/5424407 to your computer and use it in GitHub Desktop.
Documentary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** PROGRAM ASSIGNMENT 5 Documentary.java | |
* | |
* Program Description | |
* This is the Documentary class, a subclass of the Movie class. | |
* | |
*/ | |
package library.films; | |
public class Documentary extends Movie { | |
/* Declare private instance variables */ | |
private int numDistributors; | |
private double premiumAmount; | |
/* Declare private constants */ | |
private static final String CATEGORY = "documentary"; | |
/* No-arg construct for the Documentary class */ | |
public Documentary() { | |
} | |
/* Alternate constructor for the Documentary class */ | |
public Documentary(String title, String director, int year, | |
double productionCost, int numDistributors, double premiumAmount) { | |
super(title, director, year, productionCost); | |
this.numDistributors = numDistributors; | |
this.premiumAmount = premiumAmount; | |
} | |
/* Accessor method for numDistributors data field */ | |
public int getNumDistributors() { | |
return numDistributors; | |
} | |
/* Mutator method for numDistributors data field */ | |
public void setNumDistributors(int numDistributors) { | |
this.numDistributors = numDistributors; | |
} | |
/* Accessor method for premiumAmount data field */ | |
public double getPremiumAmount() { | |
return premiumAmount; | |
} | |
/* Mutator method for premiumAmount data field */ | |
public void setPremiumAmount(double premiumAmount) { | |
this.premiumAmount = premiumAmount; | |
} | |
/* Overriden abstract method to retrieve category */ | |
public String getCategory() { | |
return CATEGORY; | |
} | |
/* Overriden abstract method to calculate revenue */ | |
public double calcRevenue() { | |
return numDistributors * premiumAmount; | |
} | |
/* Overriden abstract method to calculate profit */ | |
public double calcProfit() { | |
return calcRevenue() - super.getProductionCost(); | |
} | |
/* Overriden toString method */ | |
public String toString() { | |
String fromParent = super.toString(); | |
String fromMe = String.format("This is a documentary movie, and it is" | |
+ " %s", getProfitability()); | |
return fromParent + " " + fromMe; | |
} | |
/* Effector helper method to determine profitability */ | |
private String getProfitability() { | |
if (calcProfit() > 0) { | |
return "profitable."; | |
} | |
else { | |
return "not profitable."; | |
} | |
} | |
} // end of class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment