Created
April 20, 2013 04:13
-
-
Save csabatini/5424722 to your computer and use it in GitHub Desktop.
Animated.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 Animated.java | |
* | |
* Program Description | |
* This is the Animated class, a subclass of the Movie class. | |
* | |
*/ | |
package library.films; | |
public final class Animated extends Movie { | |
/* Declare private instance variables */ | |
private double royaltyRate; | |
private double income; | |
/* Declare private constants */ | |
private static final String CATEGORY = "animated"; | |
/* No-arg construct for the Animated class */ | |
public Animated() { | |
} | |
/* Alternate constructor for the Animated class */ | |
public Animated(String title, String director, int year, | |
double productionCost, double royaltyRate, double income) { | |
super(title, director, year, productionCost); | |
this.royaltyRate = royaltyRate; | |
this.income = income; | |
} | |
/* Accessor method for royaltyRate data field */ | |
public double getRoyaltyRate() { | |
return royaltyRate; | |
} | |
/* Mutator method for royaltyRate data field */ | |
public void setRoyaltyRate(double royaltyRate) { | |
this.royaltyRate = royaltyRate; | |
} | |
/* Accessor method for income data field */ | |
public double getIncome() { | |
return income; | |
} | |
/* Mutator method for income data field */ | |
public void setIncome(double income) { | |
this.income = income; | |
} | |
/* Overriden abstract method to return category */ | |
public String getCategory() { | |
return CATEGORY; | |
} | |
/* Overriden abstract method to calculate revenue */ | |
public double calcRevenue() { | |
return income * royaltyRate; | |
} | |
/* Overriden abstract method to calculate revenue */ | |
public double calcProfit() { | |
return calcRevenue() - super.getProductionCost(); | |
} | |
/* Overridden toString effector method */ | |
public String toString() { | |
String fromParent = super.toString(); | |
String fromMe = String.format("This is an animated movie, and it is " | |
+ "%s", getProfitability()); | |
return fromParent + " " + fromMe; | |
} | |
/* 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