Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Model.
- *
- * @author Catherine
- * @version 1.0
- */
- public class Model
- {
- public static final int IN_PER_FOOT = 12;
- public static final double CM_PER_INCH = 2.54;
- public static final double LBS_PER_KILO = 2.2;
- public static final int BASE_RATE = 300;
- public static final int TALL_CM = 190;
- public static final int TALL_FIT_BONUS = 50;
- public static final int TRAVEL_BONUS = 40;
- public static final int SMOKER_DEDUCTION = 150;
- private static int employeeCounter = 0;
- private String name;
- private String surname;
- private int heightInCentimetres;
- private boolean worksOut;
- private boolean canTravel;
- private boolean smokesCigarettes;
- private int employeeNumber;
- /**
- * Default constructor for objects of class Model
- */
- public Model()
- {
- name = "";
- surname = "";
- heightInCentimetres = 0;
- worksOut = false;
- canTravel = false;
- smokesCigarettes = false;
- employeeCounter++;
- employeeNumber = employeeCounter;
- }
- /**
- * Non-default constructor for objects of class Model
- * @param newName
- * @param newSurname
- * @param newHeightInCentimetres
- * @param newWorksOut
- * @param newCanTravel
- * @param newSmokesCigarettes
- */
- public Model(String newName,
- String newSurname,
- int newHeightInCentimetres,
- boolean newWorksOut,
- boolean newCanTravel,
- boolean newSmokesCigarettes)
- {
- setName(newName);
- setSurname(newSurname);
- setWorksOut(newWorksOut);
- setCanTravel(newCanTravel);
- setSmokesCigarettes(newSmokesCigarettes);
- employeeCounter++;
- employeeNumber = employeeCounter;
- }
- /**
- * Returns the model's employee number.
- * @return employeeNumber as an int.
- */
- private int getEmployeeCounter() {
- return employeeCounter;
- }
- /**
- * Returns name.
- * @return name as a String
- */
- public String getName()
- {
- return name;
- }
- /**
- * Returns surname.
- * @return surname as a String
- */
- public String getSurame()
- {
- return surname;
- }
- /**
- * Returns height in centimetres.
- * @return heightInCentimetres as an int
- */
- public int getHeightInCentimetres()
- {
- return heightInCentimetres;
- }
- /**
- * Returns whether or not the model works out.
- * @return worksOut as a boolean
- */
- public boolean getWorksOut()
- {
- return worksOut;
- }
- /**
- * Returns whether or not the model can travel.
- * @return canTravel as a boolean
- */
- public boolean getCanTravel()
- {
- return canTravel;
- }
- /**
- * Returns whether or not the model smokes.
- * @return smokesCigarettes as a boolean
- */
- public boolean getSmokesCigarettes()
- {
- return smokesCigarettes;
- }
- /**
- * Sets name.
- * @param name of model
- */
- public final void setName(String name)
- {
- if (name != null && name.trim().length() > 0){
- this.name = name.trim();
- }
- }
- /**
- * Sets surname.
- * @param surname of model
- */
- public final void setSurname(String surname)
- {
- if (surname != null && surname.trim().length() > 0){
- this.surname = surname.trim();
- }
- }
- /**
- * Sets height of model in centimetres.
- * @param height of model in centimetres
- */
- public final void setHeightInCentimetres(int heightInCentimetres)
- {
- if (heightInCentimetres >= 0 && heightInCentimetres <= TALL_CM) {
- this.heightInCentimetres = heightInCentimetres;
- }
- }
- /**
- * Sets whether or not the model works out.
- * @param true if the model works out
- */
- public final void setWorksOut(boolean worksOut)
- {
- this.worksOut = worksOut;
- }
- /**
- * Sets whether not the model can travel.
- * @param true if the model can travel
- */
- public final void setCanTravel(boolean canTravel)
- {
- this.canTravel = canTravel;
- }
- /**
- * Sets whether or not the model smokes.
- * @param true if the model smokes
- */
- public final void setSmokesCigarettes(boolean smokesCigarettes)
- {
- this.smokesCigarettes = smokesCigarettes;
- }
- /**
- * Returns the model's height in feet and inches.
- * @return heightToFeetAndInches the model's height in feet and inches
- */
- public String convertHeightToFeetAndInches(){
- int heightInInches = (int)(heightInCentimetres/CM_PER_INCH);
- int heightInFeet = heightInInches/IN_PER_FOOT;
- int remainderInches = heightInInches%IN_PER_FOOT;
- return heightInFeet + " feet " + remainderInches + " inches.";
- }
- /**
- * Returns hourly rate of a model after factoring in attributes
- * @return hourlyRate as an int
- */
- public int calculateHourlyRate(){
- int hourlyRate = BASE_RATE;
- if (heightInCentimetres >= TALL_CM && worksOut == true){
- hourlyRate += TALL_FIT_BONUS;
- }
- if (canTravel == true){
- hourlyRate += TRAVEL_BONUS;
- }
- if (smokesCigarettes == true){
- hourlyRate -= SMOKER_DEDUCTION;
- }
- return hourlyRate;
- }
- /**
- * Returns concatenated string of all fields of the model
- * @return string value of all model attributes
- */
- public String toString(){
- String description = "";
- if (name != null && name.trim().length() > 0) {
- description = description + name + " ";
- }
- else {
- description = description + "(no name) ";
- }
- if (surname != null && surname.trim().length() > 0) {
- description = description + surname + " ";
- }
- else {
- description = description + "(no surname) ";
- }
- description = description + heightInCentimetres + "cm ";
- if (worksOut == true) {
- description = description + "works out ";
- }
- else {
- description = description + "doesn't work out ";
- }
- if (canTravel == true) {
- description = description + "can travel ";
- }
- else {
- description = description + "cannot travel ";
- }
- if (smokesCigarettes == true) {
- description = description + "smokes ";
- }
- else {
- description = description + "does not smoke ";
- }
- return description;
- }
- /**
- * Displays concatenated string of all fields of a model
- */
- public void displayModel(){
- System.out.println(toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement