Advertisement
Guest User

Untitled

a guest
May 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1.  
  2. /**
  3. * Model.
  4. *
  5. * @author Catherine
  6. * @version 1.0
  7. */
  8. public class Model
  9. {
  10. public static final int IN_PER_FOOT = 12;
  11. public static final double CM_PER_INCH = 2.54;
  12. public static final double LBS_PER_KILO = 2.2;
  13. public static final int BASE_RATE = 300;
  14. public static final int TALL_CM = 190;
  15. public static final int TALL_FIT_BONUS = 50;
  16. public static final int TRAVEL_BONUS = 40;
  17. public static final int SMOKER_DEDUCTION = 150;
  18.  
  19. private static int employeeCounter = 0;
  20.  
  21. private String name;
  22. private String surname;
  23. private int heightInCentimetres;
  24. private boolean worksOut;
  25. private boolean canTravel;
  26. private boolean smokesCigarettes;
  27.  
  28. private int employeeNumber;
  29.  
  30. /**
  31. * Default constructor for objects of class Model
  32. */
  33. public Model()
  34. {
  35. name = "";
  36. surname = "";
  37. heightInCentimetres = 0;
  38. worksOut = false;
  39. canTravel = false;
  40. smokesCigarettes = false;
  41.  
  42. employeeCounter++;
  43. employeeNumber = employeeCounter;
  44. }
  45.  
  46. /**
  47. * Non-default constructor for objects of class Model
  48. * @param newName
  49. * @param newSurname
  50. * @param newHeightInCentimetres
  51. * @param newWorksOut
  52. * @param newCanTravel
  53. * @param newSmokesCigarettes
  54. */
  55. public Model(String newName,
  56. String newSurname,
  57. int newHeightInCentimetres,
  58. boolean newWorksOut,
  59. boolean newCanTravel,
  60. boolean newSmokesCigarettes)
  61. {
  62. setName(newName);
  63.  
  64. setSurname(newSurname);
  65.  
  66. setWorksOut(newWorksOut);
  67.  
  68. setCanTravel(newCanTravel);
  69.  
  70. setSmokesCigarettes(newSmokesCigarettes);
  71.  
  72. employeeCounter++;
  73.  
  74. employeeNumber = employeeCounter;
  75. }
  76.  
  77. /**
  78. * Returns the model's employee number.
  79. * @return employeeNumber as an int.
  80. */
  81. private int getEmployeeCounter() {
  82. return employeeCounter;
  83. }
  84.  
  85. /**
  86. * Returns name.
  87. * @return name as a String
  88. */
  89. public String getName()
  90. {
  91. return name;
  92. }
  93.  
  94. /**
  95. * Returns surname.
  96. * @return surname as a String
  97. */
  98. public String getSurame()
  99. {
  100. return surname;
  101. }
  102.  
  103. /**
  104. * Returns height in centimetres.
  105. * @return heightInCentimetres as an int
  106. */
  107. public int getHeightInCentimetres()
  108. {
  109. return heightInCentimetres;
  110. }
  111.  
  112. /**
  113. * Returns whether or not the model works out.
  114. * @return worksOut as a boolean
  115. */
  116. public boolean getWorksOut()
  117. {
  118. return worksOut;
  119. }
  120.  
  121. /**
  122. * Returns whether or not the model can travel.
  123. * @return canTravel as a boolean
  124. */
  125. public boolean getCanTravel()
  126. {
  127. return canTravel;
  128. }
  129.  
  130. /**
  131. * Returns whether or not the model smokes.
  132. * @return smokesCigarettes as a boolean
  133. */
  134. public boolean getSmokesCigarettes()
  135. {
  136. return smokesCigarettes;
  137. }
  138.  
  139. /**
  140. * Sets name.
  141. * @param name of model
  142. */
  143. public final void setName(String name)
  144. {
  145. if (name != null && name.trim().length() > 0){
  146. this.name = name.trim();
  147. }
  148. }
  149.  
  150. /**
  151. * Sets surname.
  152. * @param surname of model
  153. */
  154. public final void setSurname(String surname)
  155. {
  156. if (surname != null && surname.trim().length() > 0){
  157. this.surname = surname.trim();
  158. }
  159. }
  160.  
  161. /**
  162. * Sets height of model in centimetres.
  163. * @param height of model in centimetres
  164. */
  165. public final void setHeightInCentimetres(int heightInCentimetres)
  166. {
  167. if (heightInCentimetres >= 0 && heightInCentimetres <= TALL_CM) {
  168. this.heightInCentimetres = heightInCentimetres;
  169. }
  170. }
  171.  
  172. /**
  173. * Sets whether or not the model works out.
  174. * @param true if the model works out
  175. */
  176. public final void setWorksOut(boolean worksOut)
  177. {
  178. this.worksOut = worksOut;
  179. }
  180.  
  181. /**
  182. * Sets whether not the model can travel.
  183. * @param true if the model can travel
  184. */
  185. public final void setCanTravel(boolean canTravel)
  186. {
  187. this.canTravel = canTravel;
  188. }
  189.  
  190. /**
  191. * Sets whether or not the model smokes.
  192. * @param true if the model smokes
  193. */
  194. public final void setSmokesCigarettes(boolean smokesCigarettes)
  195. {
  196. this.smokesCigarettes = smokesCigarettes;
  197. }
  198.  
  199. /**
  200. * Returns the model's height in feet and inches.
  201. * @return heightToFeetAndInches the model's height in feet and inches
  202. */
  203.  
  204. public String convertHeightToFeetAndInches(){
  205. int heightInInches = (int)(heightInCentimetres/CM_PER_INCH);
  206. int heightInFeet = heightInInches/IN_PER_FOOT;
  207. int remainderInches = heightInInches%IN_PER_FOOT;
  208.  
  209. return heightInFeet + " feet " + remainderInches + " inches.";
  210. }
  211.  
  212. /**
  213. * Returns hourly rate of a model after factoring in attributes
  214. * @return hourlyRate as an int
  215. */
  216. public int calculateHourlyRate(){
  217. int hourlyRate = BASE_RATE;
  218.  
  219. if (heightInCentimetres >= TALL_CM && worksOut == true){
  220. hourlyRate += TALL_FIT_BONUS;
  221. }
  222.  
  223. if (canTravel == true){
  224. hourlyRate += TRAVEL_BONUS;
  225. }
  226.  
  227. if (smokesCigarettes == true){
  228. hourlyRate -= SMOKER_DEDUCTION;
  229. }
  230.  
  231. return hourlyRate;
  232. }
  233.  
  234. /**
  235. * Returns concatenated string of all fields of the model
  236. * @return string value of all model attributes
  237. */
  238. public String toString(){
  239. String description = "";
  240. if (name != null && name.trim().length() > 0) {
  241. description = description + name + " ";
  242. }
  243. else {
  244. description = description + "(no name) ";
  245. }
  246.  
  247. if (surname != null && surname.trim().length() > 0) {
  248. description = description + surname + " ";
  249. }
  250. else {
  251. description = description + "(no surname) ";
  252. }
  253.  
  254. description = description + heightInCentimetres + "cm ";
  255.  
  256. if (worksOut == true) {
  257. description = description + "works out ";
  258. }
  259. else {
  260. description = description + "doesn't work out ";
  261. }
  262.  
  263. if (canTravel == true) {
  264. description = description + "can travel ";
  265. }
  266. else {
  267. description = description + "cannot travel ";
  268. }
  269.  
  270. if (smokesCigarettes == true) {
  271. description = description + "smokes ";
  272. }
  273. else {
  274. description = description + "does not smoke ";
  275. }
  276.  
  277. return description;
  278. }
  279.  
  280. /**
  281. * Displays concatenated string of all fields of a model
  282. */
  283. public void displayModel(){
  284. System.out.println(toString());
  285. }
  286.  
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement