Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Models a newborn with a name and a length
- */
- public class Newborn implements Comparable
- {
- private String name;
- private double length;
- /**
- * Constructs a new born baby
- * @param name the Newborn's name
- * @param length the length of the Newborn
- */
- public Newborn(String name, double length)
- {
- this.name = name;
- this.length = length;
- }
- /**
- * Gets the Newborn's name
- * @return the name of the Newborn
- */
- public String getName()
- {
- return name;
- }
- /**
- * Gets the Newborn's length
- * @return the length of the Newborn
- */
- public double getLength()
- {
- return length;
- }
- /**
- * Sets a new name for the Newborn
- * @param newName the new name for the Newborn
- */
- public void setName(String newName)
- {
- name = newName;
- }
- /**
- * Sets a new length for the Newborn
- * @param length the new length for the Newborn
- */
- public void setLength(double length)
- {
- this.length = length;
- }
- /**
- * @Override
- */
- public int compareTo(Object otherObject)
- {
- Newborn newStuff =(Newborn)otherObject;
- if(length < newStuff.getLength())
- return -1;
- else if(length > newStuff.getLength())
- return 1;
- else
- return name.compareTo(newStuff.getName());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement