Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 2 tests your knowledge of Decisions Structures ( Chapter 4 ) , repetition structures / Loops ( Chapter 5 ) and Classes and Objects

Assignment 2 tests your knowledge of Decisions Structures (Chapter 4), repetition structures/Loops (Chapter 5) and Classes and Objects in Java (Chapter 6) and should be solved using concepts learned in class so far (Chapters 1 to 6) and requirements bellow.
Design a class called YourNameMonth, replace YourName with your actual name) with the (exact) fields and methods ?1 :
\table[[Field/Method,Description,,,,,,,,,,,],[Number,An integral field that holds the number of the month which is a value between 1 and 12 where],[\table[[Number,1]],2,3,4,5,6,7,8,9,10,11,12],[\table[[Corresponding January],[Name]],February,March,April,May,June,July,August,September,October,November,December],[YourNameMonth,A no-argument constructor that sets the Number field to 1],[YourNameMonth,\table[[A constructor with one integral parameter representing the number of the month , etc.) and sets the Number],[field to that value. If a value less than 1 or larger that 12 is passed, the constructor should set Number to]]],[YourNameMonth,\table[[A constructor with one string parameter representing the name of the month ("January", "February", etc.) that sets],[the Number field to the corresponding number. If the value is invalid (less than 1 or larger than 12), should set],[Number to 1. You should NOT add another field for the name of the month.]]],[YourNameMonth,A copy constructor that copies the Number field value from another month object.],[getNumber,An integral method that returns the Number field value],[setNumber,A void method with an integral parameter that sets the Number field to that integral number],[getName,A String method that returns the name of the month corresponding to the Number field value],[toString,A string method that returns a string with this format: "Month is NUMBER" where NUMBER is the field Number],[equals,\table[[A Boolean method that accepts a YourNameMonth object Month2 as an argument and returns true if the data from],[that object (its Number) is the same as the Number field of Month2 or false otherwise.]]],[compareio,\table[[An integral method that accepts a Month object Month2as an argument and returns if Number value from the class],[is the same as the number from the Month2 object, -1 if it is smaller, and 1 if it is larger.]]]]
Design a driver class called YourNameAssignment2(replace YourName with your actual name) in the same project as the YourNameMonth. You will need to add the class Month to the project and add your code to the project class main method. The program (code) should:
Create three objects: Month 1 using the first no-arg constructor, Month2 using the second constructor with 2 as an argument, Month3 using the third constructor with "October" as an argument, and Month4 using the fourth/copy constructor from Month3.
Use the getNumber to get the month number from objects Monthl, Month2, Month3, and Month4 and output the them.
Use the getName to get the month name from objects Month1, Month2, Month3, and Month4 and output them.
Use the setNumber to set the Monthl object value to 10.
Use the toString to get the month string from objects Month1, Month2, Month3, and Month4 and output them.
Use the equals method of Month1 to compare its value with Month2 value and output the result.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

How can the Internet be helpful in a job search? (Objective 2)

Answered: 1 week ago