Question: Write A class named Month. The class should have an int field named monthNumber that holds the number of the month. For example, January would

Write A class named Month. The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods: A no-arg constructor that sets the monthNumber field to I. A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than I or greater than 12 is passed, the constructor should set monthNumber to I. A constructor that accepts the name of the month, such as "January" or "February" as an argument. It should set the monthNumber field to the correct corresponding value, A setMonthNumber method that accepts an i n t argument, which is assigned to the monthNumber field. If a value less than 1 or greater than 12 is passed, the method should set monthNumber to 1. A getMonthNumber method that returns the value in the monthNumber field. A getMonthName method that returns the name of the month. For example, if the monthNumber field contains 1, then this method should return "January". A toString method that returns the same value as the getMonthName method. An equals method that accepts a Month object as an argument. If the argument object holds the same data as the calling object, this method should return true. Otherwise, it should return false. A greaterThan method that accepts a Month object as an argument. If the calling objects monthNumber field is greater than the argument's monthNumber fields this method should return true. Otherwise, it should return false. A less Than method that accepts a Month object as an argument. If the calling object's monthNumber field is less than the arguments monthNumber field, this method should return true. Otherwise, it should return false. I manage to write this program in neatbeans. However, it says no Main Method Found? ** * * @author VictorPC */ public class Month { private int monthNumber; private int Month; /** * no-arg construction */ public Month() { monthNumber=1; } /** * month number constructor * @param number */ public Month(int number) { monthNumber = setMonthNumber(number); } /**month name constructor * @param months */ public Month(String m) { String upper = m.toUpperCase(); if(upper.equals("JANUARY")) monthNumber = setMonthNumber(1); else if (upper.equals("FEBURARY")) monthNumber=setMonthNumber(2); if(upper.equals("MARCH")) monthNumber = setMonthNumber(3); else if (upper.equals("APRIL")) monthNumber=setMonthNumber(4); if(upper.equals("MAY")) monthNumber = setMonthNumber(5); else if (upper.equals("JUNE")) monthNumber=setMonthNumber(6); if(upper.equals("JULY")) monthNumber = setMonthNumber(7); else if (upper.equals("AUGUST")) monthNumber=setMonthNumber(8); if(upper.equals("SEPTEMBER")) monthNumber = setMonthNumber(9); else if (upper.equals("OCTOBER")) monthNumber=setMonthNumber(10); if(upper.equals("NOVEMBER")) monthNumber = setMonthNumber(11); else if (upper.equals("DECEMBER")) monthNumber=setMonthNumber(12); } /** * monthNumber Mutator * @param number */ public int setMonthNumber(int number) { //input validation //Valid input 1-12 otherwise default to 1 if ((number >= 1)&&(number<=12)) return number; else return 1; } /** * accessor for monthNumber * @return monthNumber */ public int getMonthNumber() { return monthNumber; } /** * Month Name generator * @return monthNumber */ public String getMonthName() { switch (monthNumber) { case 1: return "JANUARY"; case 2: return "FEBRURARY"; case 3: return "MARCH"; case 4: return "APRIL"; case 5: return "MAY"; case 6: return "JUNE"; case 7: return "JULY"; case 8: return "AUGUST"; case 9: return "SEPTEMBER"; case 10: return "OCTOBER"; case 11: return "NOVEMBER"; case 12: return "DECEMBER"; default: return "JANUARY"; } } /**toString Overload * */ public String toString() { return getMonthName(); } /** * comparison of passed object with current object * to determine equality * @param m * @return boolean */ public boolean equals(Month m) { if(m.getMonthNumber()== this.getMonthNumber()) return true; else return false; } /** * comparison of passed object with current object * to determine equality * @param m * @return boolean * */ public boolean greaterThen(Month m) { if(this.getMonthNumber()>m.getMonthNumber()) return true; else return false; } /** * comparison of passed object with current object * to determine equality * @param m * @return boolean */ public boolean lessThen(Month m) { if(this.getMonthNumber()< m.getMonthNumber()) return true; else return false; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!