Created
April 20, 2013 02:07
-
-
Save csabatini/5424405 to your computer and use it in GitHub Desktop.
Drama.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 Drama.java | |
* | |
* Program Description | |
* This is the Drama class, a subclass of the Movie class. | |
* | |
*/ | |
package library.films; | |
public class Drama extends Movie { | |
/* Declare private instance variables */ | |
private int ticketsSold; | |
private double ticketPrice; | |
/* Declare private constants */ | |
private static final String CATEGORY = "drama"; | |
/* No-arg construct for the Drama class */ | |
public Drama() { | |
} | |
/* Alternate constructor for the Drama class */ | |
public Drama(String title, String director, int year, | |
double productionCost, int ticketsSold, double ticketPrice) { | |
super(title, director, year, productionCost); | |
this.ticketsSold = ticketsSold; | |
this.ticketPrice = ticketPrice; | |
} | |
/* Accessor method for ticketsSold data field */ | |
public int getTicketsSold() { | |
return ticketsSold; | |
} | |
/* Mutator method for ticketsSold data field */ | |
public void setTicketsSold(int ticketsSold) { | |
this.ticketsSold = ticketsSold; | |
} | |
/* Accessor method for ticketPrice data field */ | |
public double getTicketPrice() { | |
return ticketPrice; | |
} | |
/* Mutator method for ticketPrice data field */ | |
public void setTicketPrice(double ticketPrice) { | |
this.ticketPrice = ticketPrice; | |
} | |
/* /* Overriden abstract method to retrieve category */ | |
public String getCategory() { | |
return CATEGORY; | |
} | |
/* Overriden abstract method to calculate revenue */ | |
public double calcRevenue() { | |
return ticketsSold * ticketPrice; | |
} | |
/* 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 drama 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