Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab01;
- /**
- * Tree Class
- * Models a tree
- * @author Chad Humphries
- * @version Lab01
- * Date Created: Sept 14, 2019
- */
- public class Tree
- {
- //Constants
- public static final String DEFAULT_TYPE = "n/a";
- public static final int JANUARY = 1;
- public static final int DECEMBER = 12;
- public static final int CURRENT_YEAR = 2019;
- //Variables
- private String type = DEFAULT_TYPE;
- private int month = JANUARY;
- private int year = CURRENT_YEAR;
- /**
- * Default Constructor
- */
- public Tree()
- {
- }
- /**
- * Overloaded Constructor
- * @param type Type of tree
- * @param month Month planted
- * @param year Year planted
- */
- public Tree(String type, int month, int year)
- {
- setType(type);
- setMonth(month);
- setYear(year);
- }
- /**
- * Mutator for tree type
- * @param type Type of tree
- * If type is null, DEFAULT_TYPE will be assigned
- */
- public void setType(String type)
- {
- if(type != null && type.trim().length() > 0)
- {
- this.type = type;
- }
- else
- {
- this.type = DEFAULT_TYPE;
- }
- }
- /**
- * Mutator for month planted
- * @param month Month planted
- * If month is less than JANUARY or greater than DECEMBER, JANUARY will be assigned
- */
- public void setMonth(int month)
- {
- if(month >= JANUARY && month <= DECEMBER)
- {
- this.month = month;
- }
- else
- {
- this.month = JANUARY;
- }
- }
- /**
- * Mutator for year planted
- * @param year Year planted
- * if year is negative or greater than CURRENT_YEAR, CURRENT_YEAR will be assigned
- */
- public void setYear(int year)
- {
- if(year >= 0 && year <= CURRENT_YEAR)
- {
- this.year = year;
- }
- else
- {
- this.year = CURRENT_YEAR;
- }
- }
- /**
- * Accessor for type
- * @return Type of tree
- */
- public String getType()
- {
- return type;
- }
- /**
- * Accessor for month
- * @return Month planted
- */
- public int getMonth()
- {
- return month;
- }
- /**
- * Accessor for year
- * @return Year planted
- */
- public int getYear()
- {
- return year;
- }
- /**
- * Prints details about tree
- */
- public void showDetails()
- {
- System.out.println("Tree Info: " +
- "\nType: " + getType() +
- "\nMonth planted: " + getMonth() +
- "\nYear planted: " + getYear() +
- "\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement