All files require Javadoc documentation comments at
the top to include a description of the program and an @author tag
with your name only.
--------------------------------------
Develop an exception class
named InvalidMonthException that extends
the Exception class. Instances of the class
will be thrown based on the following conditions:
The value for a month number is not between 1 and
12
The value for a month name is not January, February,
March, … December
--------------------------------------
Develop a class named Month. The
class should define an integer field
named monthNumber that holds the number of a month.
For example, January would be 1, February would be 2, and so
forth. In addition, provide the following methods:
A no-argument constructor that sets
the monthNumberto 1.
An overloaded constructor that accepts the number of
the month as an argument. The constructor should set
the monthNumberfield to the parameter value if the parameter
contains the value 1 – 12. Otherwise, throw
an InvalidMonthException exception back to the
caller. The exception should note that the month number was
incorrect.
An overloaded constructor that accepts a string
containing the name of the month, such as “January” and sets
the monthNumberbased on the parameter string. When the
parameter value does not match a valid name of a month, the
constructor throws an InvalidMonthException exception
back to the caller. The exception should note an invalid
month name was used.
Accessor and mutator methods for the monthNumber
The mutator method must validate
the monthNumber parameter and throw
an InvalidMonthException exception back to the caller
when an invalid value is given.
A getMonthNamemethod that returns the name of the
month based upon the monthNumber
A toStringmethod that returns the same value as
the getMonthName
An equalsmethod that accepts
a Month object as a parameter and compares the object to
the calling object to determine if the objects contain the same
value for the monthNumber
--------------------------------------
Develop a test client to thoroughly test
the Month class and handle the exceptions
thrown.
Hey There!! Please edit the statement : @author PleaseWriteYourNameHere in all the below mentioned files and write you own name in place of PleaseWriteYourNameHere .
Also, Please comment if you have doubts or need
modification.
InvalidMonthException class:
/*
* InvalidMonthException class is an user defined class that hadles
invalid month paased
*/
/**
*
* @author PleaseWriteYourNameHere
*/
public class InvalidMonthException extends Exception{
String error;
//constructor
InvalidMonthException(String error){
this.error=error;
}
public String toString(){
return error;
}
}
Month class:
/*
* Month class handles the month of a calendar and throw excpetion
when an invalid mont is handled
*/
/**
*
* @author PleaseWriteYourNameHere
*/
public class Month {
//integer field
private int monthNumber ;
//no-argument constructor
public Month(){
this.monthNumber=1;
}
//overloaded constructor that accepts the number
of the month as an argument.
public Month(int number)throws
InvalidMonthException{
//throws exception if
monthNumber paased is not valid
if (number<1
||number>12) throw new InvalidMonthException("The value for a
month number is not between 1 and 12");
else
this.monthNumber=number;
}
//An overloaded constructor that accepts a
string containing the name of the month, such as “January” and sets
the monthNumberbased on the parameter string.
public Month(String monthName)throws
InvalidMonthException{
switch
(monthName){
case "January":
this.monthNumber=1;
break;
case "February":
this.monthNumber=2;
break;
case "March":
this.monthNumber=3;
break;
case "April":
this.monthNumber=4;
break;
case "May":
this.monthNumber=5;
break;
case "June":
this.monthNumber=6;
break;
case "July":
this.monthNumber=7;
break;
case "August":
this.monthNumber=8;
break;
case "September":
this.monthNumber=9;
break;
case "October":
this.monthNumber=10;
break;
case "November":
this.monthNumber=11;
break;
case "Decemeber":
this.monthNumber=12;
break;
//throw exception when an inappropriate month is paased i.e. if
none of the above case is executed
default:
throw new InvalidMonthException("The value for a month name is not
January, February, March, … December");
}
}
//accessor
public int getMonthNumber() {
return
monthNumber;
}
//setter
public void setMonthNumber(int
monthNumber)throws InvalidMonthException {
if (monthNumber<1
||monthNumber>12) throw new InvalidMonthException("The value for
a month number is not between 1 and 12");
this.monthNumber=monthNumber;
}
//accessor
public String getMonthName(){
String name="";
switch
(monthNumber){
case 1:
name="January";
break;
case 2:
name="February";
break;
case 3:
name="March";
break;
case 4:
name="April";
break;
case 5:
name="May";
break;
case 6:
name="June";
break;
case 7:
name="July";
break;
case 8:
name="August";
break;
case 9:
name="September";
break;
case 10:
name="October";
break;
case 11:
name="November";
break;
case 12:
name="Decemeber";
break;
}
return name;
}
//compares the monthNumber of two objects
public void equals(Month object){
if
(this.monthNumber==object.monthNumber){
System.out.println("The object contains the same month
number");
}
else
System.out.println("The object does not contains the same month
number");
}
@Override
public String toString() {
return
getMonthName();
}
}
MonthTest:
/*
* MonthTest class thoroughly test the execution of Month class and
InvalidMonthException class
*/
/**
* @author PleaseWriteYourNameHere
*/
public class MonthTest {
public static void main(String[] args)
{
//create constructor of Month
class that will invoke the default
constructor
Month obj=new
Month();
//display the
month
System.out.println(obj);
try{
Month obj1=new Month("January");
System.out.println(obj1);
//check whether the monthNumber for the two objects is same
obj.equals(obj1);
Month obj2=new Month(4);
System.out.println(obj2);
obj.equals(obj2);
//This will throw exception , hence statements after it will not be
executed
Month obj3=new Month("Sep");
System.out.println(obj3);
obj.equals(obj3);
}
catch
(InvalidMonthException ex){
System.out.println(ex);
}
try{
//This will throw exception , hence statements after it will not be
executed
Month obj4=new Month(15);
System.out.println(obj4);
obj.equals(obj4);
}
catch
(InvalidMonthException ex){
System.out.println(ex);
}
}
}
Output:
All files require Javadoc documentation comments at the top to include a description of the program...
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 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...
Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help. Specifications: 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 1. A constructor that accepts the number of the month as an argument. It should...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
Design a class named Month. The class should have the following private members: • name - A string object that holds the name of a month, such as "January", "February", etc. • monthNumber - An integer variable that holds the number of the month. For example, January would be 1, February would be 2, etc. Valid values for this variable are 1 through 12. In addition, provide the following member functions:• A default constructor that sets monthNumber to 1 and name...
Create a simple Java class for a Month object with the following requirements: This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does. All methods will have comments concerning their purpose, their inputs, and their outputs One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
put everything together in an object-oriented manner! create a class named PositiveNumberStatistics that has the following: A private double 1D array instance variable named numbers. A constructor that takes one parameter, a 1D double array. The constructor should throw an IllegalArgumentException with the message "Array length of zero" if the parameter has a length of 0. If the exception is not thrown, the constructor should create the numbers array and copy every element from the parameter into the numbers instance...
Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....
JAVA PROG HW Problem 1 1. In the src −→ edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: ApublicstaticmethodnamedfindIntegerthattakesaStringandtwocharvariables as parameters (in that order) and does not return anything. The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the firstchar parameter. However, you cannot assume that the parameters will be different from...
a) Create an abstract class Student. The class contains fields for student Id number, name, and tuition. Includes a constructor that requires parameters for the ID number and name. Include get and set method for each field; setTuition() method is abstract. b) The Student class should throw an exception named InvalidNameException when it receives an invalid student name (student name is invalid if it contains digits). c) Create three student subclasses named UndergradStudent, GradeStudent, and StudentAtLarge, each with a unique...
This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...