Question: 7. a. Write a class named Month. The data members of the class should have an int field named month Number that holds the month

7. a. Write a class named Month. The data members of the class should have an int field named month Number that holds the month number. For example, January would be 1, February would be 2. and so forth. It has an String array containing all 12 month names: month[0] = "January, month(1) = "February", etc. public class Month private int monthNum; private String[months = {"January", "February", "March", "April", "May", "June". "July". "August", "September", "October", "November", "December"}; 7. b. Write a no-argument constructor that sets the monthNumber field to 1. public Month monthNum = 1; 7. c. Write a constructor that accepts the month number 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 monthNum) 12) if(this.monthNum >= 1 && this.monthNum this monthNum = monthNum; else monthNum = 1; 7. d. Write 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 Month(String monthName) for(int i = 2; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
