Question
I ONLY NEED HELP with the PrintName, Equals, Greater Than and Less than methods. I have attached my assignment and my code for the driver
I ONLY NEED HELP with the PrintName, Equals, Greater Than and Less than methods. I have attached my assignment and my code for the driver class and support class.
Here is my Driver:
public class gg {
public static void main(String[] args) { Month Month1 = new Month(); Month Month2 = new Month(2); Month Month3 = new Month("October"); System.out.println("Month1: "+Month1.getNumber()); System.out.println("Month2: "+Month2.getNumber()); System.out.println("Month3: "+Month3.getNumber()); System.out.println(" Month1: "+Month1.getName()); System.out.println("Month2: "+Month2.getName()); System.out.println("Month3: "+Month3.getName()); Month1.setNumber(9); Month2.setMonthName("June"); Month printn = new Month(); // AM I DOING THIS RIGHT? printn.PrintName(Name); // I Dont KNow HOW TO GO ABOUT CODING THIS PART System.out.println(" Month1: "+Month1.getName()); System.out.println("Month2: "+Month2.getName()); System.out.println("Month3: "+Month3.getName()); System.out.println(" Is month1 equal to month2 ? "+Month1.equals(Month2)); System.out.println("Is month2 greater than month3 ? "+Month2.equals(Month3)); System.out.println("Is month3 less than month1 ? "+Month3.equals(Month1)); } }
HERE IS MY CLASS
public class Month {
private int Number; public Month(){ this.Number = 1; } public Month(int Number){ if(Number> 0 && Number this.Number){ return true; } else { return false; } } public boolean lessThan(Month month){ if(month.getNumber()
}
ASSIGNMENT 2 Create a class called Month (java file called Month.java) with the (exact) following fields and methods (exact names and caps): Field/Method Description Number An int field that holds the number of the month: 1 for January, 2 for February, 3 for March, 4 for April, 5 for May, 6 for June, 7 for July, 8 for August, 9 for September, 10 for October, 11 for November, and 12 for December Month A no-argument constructor that sets the MonthNumber field to 1 Month A constructor that accept the number of the month as an argument (1, 2, 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 1 Month A constructor that accept the name of the month as an argument ("January", "February", etc) and sets the Number field to the corresponding number. If the value is invalid, should set Number to 1 GetNumber A method that returns the Number field value SetNumber | A method that accept an int number as an argument and sets the Number field to that number GetName A method that returns the name of the month corresponding to the Number field value SetName A method that accept a string value as an argument (representing the name of the month: "January". February", etc.) and sets the Number field to the corresponding number (1, 2, etc) PrintName A method that prints/outputs the name of the month corresponding to the Number field value Equals A method that accepts a Month object as an argument and returns true if the data from that object (its Number) is the same as the Number field or false otherwise Greater than A method that accepts a Month object as an argument and returns true if the data from that object (its Number) is greater than the Number field or false otherwise Less Than A method that accepts a Month object as an argument and returns true if the data from that object (its Number) is less than the Number field or false otherwise You are going to lose points if you do not name the class, the fields, or methods as requested. You should NOT have a field for the month name: your code should compute the name of the month from the number when needed. Create a program/project called Your NameAssignment2 (replace Your Name with your actual name) in the same project as the Month.java. 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: Month1 one using the first constructor (with no arguments) and Month2 using the second constructor with 2 as an argument, and Month3 using the third constructor with "october" as an argument. Use the GetNumber to get the month number from objects Month1, Month2, and Months and output the values to the console. Use the GetName to get the month name from objects Monthi, Month2, and Months and output the values to the console. Use the SetNumber to set the Monthi object value to 9. Use the SetName with argument "June" to set the Month2 object value to 6. Use the PrintName to get the month name from objects Month1, Month2, and Months and output the values to the console. Use the Equals method of Monthi to compare its value with Month2 value and output the result to the console. Use the Greater than method of Month2 to compare its value with Month value and output the result to the console. Use the LessThan method of Months to compare its value with Month1 value and output the result to the console
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started