Month Class Exceptions Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example, Janauary 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 value to the value passed as the argument. If a value less than 1 or greater than 12 is passed, the constructor should throw an InvalidMonthNumberException. 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. If an invalid name is passed, the constructor should throw an InvalidMonthNameException. 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, throw an InvalidMonthNumberException. 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 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Month Class Exceptions

Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example, Janauary 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 value to the value passed as the argument. If a value less than 1 or greater than 12 is passed, the constructor should throw an InvalidMonthNumberException.
  • 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. If an invalid name is passed, the constructor should throw an InvalidMonthNameException.
  • 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, throw an InvalidMonthNumberException.
  • 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 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.
4. Month Class Exceptions
Write a class named Month. The class should have an int field named monthNumber that holds the number of
the month. For example, Janauary 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 value
to the value passed as the argument. If a value less than 1 or greater than 12 is passed, the constructor
should throw an InvalidMonthNumber Exception.
▪ 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. If an invalid name is passed, the
constructor should throw an InvalidMonthNameException.
■
A set MonthNumber 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, throw an InvalidMonth Number Exception.
▪ 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 greater Than 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 less Than 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.
This UML diagram shows the required class design. Once you have written this class, use it in a MonthDemo
application that demonstrates the Month class.
Month
monthNumber: int
+ Month()
+ Month (n int)
+ Month(name : String)
+ setMonthNumber(mint) : void
+ getMonthNumber() : int
+ getMonthName(): String
+ toString(): String
+ equals(month2 Month): boolean
+ greaterThan(month2: Month) : boolean
+ lessThan(month2 Month): boolean
Transcribed Image Text:4. Month Class Exceptions Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example, Janauary 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 value to the value passed as the argument. If a value less than 1 or greater than 12 is passed, the constructor should throw an InvalidMonthNumber Exception. ▪ 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. If an invalid name is passed, the constructor should throw an InvalidMonthNameException. ■ A set MonthNumber 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, throw an InvalidMonth Number Exception. ▪ 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 greater Than 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 less Than 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. This UML diagram shows the required class design. Once you have written this class, use it in a MonthDemo application that demonstrates the Month class. Month monthNumber: int + Month() + Month (n int) + Month(name : String) + setMonthNumber(mint) : void + getMonthNumber() : int + getMonthName(): String + toString(): String + equals(month2 Month): boolean + greaterThan(month2: Month) : boolean + lessThan(month2 Month): boolean
▪ 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 greater Than 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 less Than 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.
This UML diagram shows the required class design. Once you have written this class, use it in a MonthDemo
application that demonstrates the Month class.
Month 3 is March
Month 4 is April
Month 5 is May
Month 6 is June
Month 7 is July
Month 8 is August
Month 9 is September
Month 10 is October
monthNumber: int
Month
+ Month()
+ Month(n: int)
+ Month(name: String)
C:\Users\Java\Desktop\Chapter
10>java Month Demo
Error Invalid number given for the month: 0
Month 1 is January
Month 2 is February
+ set MonthNumber(mint) : void
+ getMonthNumber(): int
+ getMonthName(): String
+ toString(): String
+ equals(month2: Month): boolean
+ greaterThan(month2: Month) : boolean
+ lessThan(month2 Month): boolean
Month 11 is November
Month 12 is December
Error Invalid number given for the month: 13
Error Invalid number given for the month: 25
Error Invalid name given for the month: Septober
Transcribed Image Text:▪ 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 greater Than 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 less Than 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. This UML diagram shows the required class design. Once you have written this class, use it in a MonthDemo application that demonstrates the Month class. Month 3 is March Month 4 is April Month 5 is May Month 6 is June Month 7 is July Month 8 is August Month 9 is September Month 10 is October monthNumber: int Month + Month() + Month(n: int) + Month(name: String) C:\Users\Java\Desktop\Chapter 10>java Month Demo Error Invalid number given for the month: 0 Month 1 is January Month 2 is February + set MonthNumber(mint) : void + getMonthNumber(): int + getMonthName(): String + toString(): String + equals(month2: Month): boolean + greaterThan(month2: Month) : boolean + lessThan(month2 Month): boolean Month 11 is November Month 12 is December Error Invalid number given for the month: 13 Error Invalid number given for the month: 25 Error Invalid name given for the month: Septober
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education