title: Java class 'Month' - still not getting returns... and a few other things
body: <p>New week, new assignment - new troubles I need help with!  Assignment is: 
  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. The class should also have a static field named lastMonthCreated that holds the number of the month which was last constructed. In addition, provide the following methods: </p>
  
  <p>A no-arg constructor that sets the monthNumber field to 1. 
  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 1 or greater than 12 is passed, the constructor should set monthNumber to 1. 
  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 int 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 getLastMonthCreated method that returns the value in the lastMonthCreated field. 
  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 object's monthNumber field is greater than the argument's monthNumber field, this method should return true. Otherwise, it should return false. 
  A lessThan method that accepts a Month object as an argument. If the calling object's monthNumber field is less than the argument's monthNumber field, this method should return true. Otherwise, it should return false. 
  Demonstrate the Month class by using a set of three test programs, MonthDemo1.java, MonthDemo2.java and MonthDemo3.java, which can be downloaded from the MonthDemo folder below this assignment link. </p>
  
  <p>Basically I have had a crack at this (hopefully a good one) and I'm coming up with quite a few errors when I compile - I've got them from 48 down to 6. </p>
  
  <p><strong>Errors:</strong> </p>
  
  <blockquote>
    <p>Line 47: unexpected type monthNumber = (monthName[(index + 1)++]);</p>
  </blockquote>
  
  <p>^ The error is pointing to index - so I tried creating a variable named index and initializing before using it, but no change. 
  required: variable 
  type: value </p>
  
  <blockquote>
    <p>Line 91: incompatible types, String cannot be converted to String[] if (monthName = monthName[index]) </p>
  </blockquote>
  
  <p>^ I get what this is saying but not sure how to change it to get what I need.</p>
  
  <p>^ Same error on same line again </p>
  
  <blockquote>
    <p>Line 92: cannot find symbol return getLastCreated;` </p>
  </blockquote>
  
  <p>^ I defined this at the top but didn't initialize - will it help if I do? I tried initializing to 0 and null and got errors.</p>
  
  <p>Line 93 same again </p>
  
  <p>Basically I'm looking for two things, firstly any hints for how to deal with those errors, and in general, an idea of if I'm on the right track with this, or if there are parts that need changing to make it work. If you suggest changes, do you mind suggesting the actual code and explaining why, as I'm really new and hope to learn from the suggestions not just implement. </p>
  
  <p>All your help greatly appreciated - I've learned so much from this forum over the last few weeks since starting Java! </p>
  
  <p>PS - will change case on my methods to lower - just have them upper at the moment as I find them easier to see.</p>
  
  <pre><code>    public class Month
  
  {
      private int monthNumber;
      String[] monthName = {
          "January", "Februry", "March",
              "April", "May", "June", "July", "August", "September",
              "October", "November", "December"
      }; //Months. 
      int MonthNumberInt = 0;
      public static String lastMonthCreated;
  
  
      /** 
  A no-arg constructor that sets the monthNumber field to 1. 
  */
      public Month() {
          monthNumber = 1;
      }
  
      /** 
  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 1 or greater than      
  12 is passed, the constructor  
  should set monthNumber to 1. 
  */
  
      public Month(int monthNumber) {
          if ((monthNumber &lt; 1) || (monthNumber &gt; 12)) {
              monthNumber = 1;
          } else {
              monthNumber = monthNumber;
          }
      }
  
      /** 
  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. 
  */
  
      public String Month(String monthName[]) {
          int index = 0;
          monthNumber = (monthName[(index + 1)++]);
      }
  
      /** 
  A setMonthNumber method that accepts an int 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. 
  */
  
      public int setMonthNumber(int monthNumberInt) {
          if ((monthNumber &lt; 1) || (monthNumber &gt; 12)) {
              return monthNumber = 1;
          }
          monthNumberInt = monthNumber;
      }
  
      /** 
  A getMonthNumber method that returns the value in the monthNumber field. 
  */
  
      public int getMonthNumber() {
          return monthNumber;
      }
  
      /** 
  A getMonthName method that returns the name of the month. For example, if      
  the monthNumber field contains 1,  
  then this method should return "January". 
  */
  
      public String getMonthName() {
          return monthName[monthNumber - 1];
      }
  
      /** 
  A getLastMonthCreated method that returns the value in the  
  lastMonthCreated field. 
  */
  
      public String getLastMonthCreated() {
          for (int index = 0; index &lt; monthName.length; index++) //Check through     
          the array. {
              if (monthName = monthName[index]) getLastCreated = monthName[index - 1];
              return getLastCreated;
          }
      }
  
      /** 
  A toString method that returns the same value as the getMonthName method. 
  */
      public String toString() {
          String str = "monthName: " + getMonthName();
      }
  
      /** 
  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. 
  */
  
      public boolean Equals(Month m1) //Month needs to go here.
      {
          if (monthNumber == m1.getMonthNumber()) return true;
          else return false;
      }
  
      /** 
  A greaterThan method that accepts a Month object as an argument. If the      
  calling object's monthNumber field  
  is greater than the argument's monthNumber field, this method should      
  return true. Otherwise, it should  
  return false. 
  */
  
      public boolean GreatThan(Month m1) //Month needs to go here.
      {
          if (monthNumber &gt; m1.monthNumber) return true;
          else return false;
      }
  
      /** 
  A lessThan method that accepts a Month object as an argument. If the          
  calling object's monthNumber field is  
  less than the argument's monthNumber field, this method should return      
  true. Otherwise, it should return  
  false. 
  */
  
      public boolean LesserThan(Month m1) //Month needs to go here.
      {
          if (monthNumber &lt; m1.monthNumber) return true;
          else return false;
      }
  }
  </code></pre>
  
  <p>DEMO1</p>
  
  <pre><code> public class MonthDemo1
      {
      public static void main(String[] args)
      {
        // Use the no-arg constructor.
        Month m = new Month();
        System.out.println("Month " + m.getMonthNumber() +
                           " is " + m);
        // Set the month number to the values 0 through 12
        // (0 is invalid), and display the resulting month name.
        for (int i = 0; i &lt;= 12; i++)
        {
           m.setMonthNumber(i);
           System.out.println("Month " + m.getMonthNumber() +
                           " is " + m);
        }
         }
      }
  </code></pre>
  
  <p>DEMO 2</p>
  
  <pre><code>public class MonthDemo2
      {
      public static void main(String[] args)
      {
        // Use the 2nd constructor to create two objects.
        Month m1 = new Month(10);
        Month m2 = new Month(5);
        System.out.println("Month " + m1.getMonthNumber() +
                           " is " + m1);
        System.out.println("Month " + m2.getMonthNumber() +
                           " is " + m2);
  
        // Test for equality.
        if (m1.equals(m2))
           System.out.println(m1 + " and " + m2 + " are equal.");
        else
           System.out.println(m1 + " and " + m2 + " are NOT equal.");
  
        // Is m1 greater than m2?
        if (m1.greaterThan(m2))
           System.out.println(m1 + " is greater than " + m2);
        else
           System.out.println(m1 + " is NOT greater than " + m2);
  
        // Is m1 less than m2?
        if (m1.lessThan(m2))
           System.out.println(m1 + " is less than " + m2);
        else
           System.out.println(m1 + " is NOT less than " + m2);
        }
       }
  </code></pre>
  
  <p>DEMO 3</p>
  
  <pre><code>public class MonthDemo3
      {
      public static void main(String[] args)
      {
        // Use the 3rd constructor to create three objects.
        Month m1 = new Month("March");
        Month m2 = new Month("December");
        Month m3 = new Month("Bad Month");
        System.out.println("Month " + m1.getMonthNumber() +
                           " is " + m1);
        System.out.println("Month " + m2.getMonthNumber() +
                           " is " + m2);
        System.out.println("Month " + m3.getMonthNumber() +
                           " is " + m3);
  
        Month m4 = new Month("May");
        System.out.println("The last month created" +
                           " is " + m4.getLastMonthCreated());
        }
      }
  </code></pre>