a. Create a class name Invoice that holds an invoice number, balance due, and three fields representing the month, day, and year when the database is due. Create a constructor that accepts values for all five data fields. Within the constructor, assign each argument to the appropriate field with the following exceptions:

  • If an invoice number is less than 1000, force the invoice number to 0.
  • If the month field is less than 1 or greater than 12, force the month field to 0.
  • If the day field is less than 1 or greater then 31, force the day field to 0.
  • If the year field is less than 2011 or greater than 2017, force the year field to 0.

In the Invoice class, include a display method that displays all the fields on an Invoice object. Save the file as Invoice.java.

b. Write an application containing main() method that declares several Invoice objects, proving that all the statements in the constructor operate as specified. Save the file as TestInvoice.java.

c. Modify the constructor in the Invoice class so that the day is not greater than 31, 30, or 28, depending on the month. For example, if a user tries to create an invoice for April 31, force it to April 30. Also, if the month is invalid, and thus forced to 0, also force the day to 0. Save modified Invoice class as Invoice2.java. Then modify the TestInvoice class to create Invoice2 object. Create enough objects to test every decision in the constructor. Save this file as TestInvoice2.java.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.