Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /**
  2. * Models a newborn with a name and a length
  3. */
  4. public class Newborn implements Comparable
  5. {
  6. private String name;
  7. private double length;
  8. /**
  9. * Constructs a new born baby
  10. * @param name the Newborn's name
  11. * @param length the length of the Newborn
  12. */
  13. public Newborn(String name, double length)
  14. {
  15. this.name = name;
  16. this.length = length;
  17. }
  18.  
  19. /**
  20. * Gets the Newborn's name
  21. * @return the name of the Newborn
  22. */
  23. public String getName()
  24. {
  25. return name;
  26. }
  27.  
  28. /**
  29. * Gets the Newborn's length
  30. * @return the length of the Newborn
  31. */
  32. public double getLength()
  33. {
  34. return length;
  35. }
  36.  
  37. /**
  38. * Sets a new name for the Newborn
  39. * @param newName the new name for the Newborn
  40. */
  41. public void setName(String newName)
  42. {
  43. name = newName;
  44. }
  45.  
  46. /**
  47. * Sets a new length for the Newborn
  48. * @param length the new length for the Newborn
  49. */
  50. public void setLength(double length)
  51. {
  52. this.length = length;
  53. }
  54.  
  55. /**
  56. * @Override
  57. */
  58. public int compareTo(Object otherObject)
  59. {
  60. Newborn newStuff =(Newborn)otherObject;
  61. if(length < newStuff.getLength())
  62. return -1;
  63. else if(length > newStuff.getLength())
  64. return 1;
  65. else
  66. return name.compareTo(newStuff.getName());
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement