Question

Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help.

Month Class (8 points) Write a class named Month monthNumber int Month Month (m int) Month name String) setMonthNumber (m int) void getMonthNumber(): int getMonthName(): String toString String equals(month2 Month) boolean

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 set the monthNumber field to the value passed as the argument. If a value less than 1 or greater than 12 is passed, the constructor should set monthNumber to 1.

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.

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, the method should set monthNumber to 1.

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”.

Here is my code so far:

public class Month
{

private int Month;
private int MonthNumber;
private String Name;


public setMonthNumber (int)
{
Month = 1;
}
public getMonthNumber(int)
{
return Month;
}

public getMonthName(String m)
{
if (m.equals == 1)
{
Name = "January";
}
else if (m.equals == 2)
{
Name = "Febuary";
}
else if (m.equals == 3)
{
Name = "march";
}
else if (m.equals == 4)
{
Name = "April";
}
else if (m.equals == 5)
{
Name = "may";
}
else if (m.equals == 6)
{
Name = "june";
}
else if (m.equals == 7)
{
Name = "july";
}
else if (m.equals == 8)
{
Name = "August";
}
else if (m.equals == 9)
{
Name = "september";
}
else if (m.equals == 10)
{
Name = "october";
}
else if (m.equals == 11)
{
Name = "novermber";
}
else if (m.equals == 12)
{
Name = "December";
}
  
}
public boolean CorrectMonth()
{
if(Month == 1)
{
return true;
}
else
{
return false;
}
}

System.out.println("The month is: " + getMonthName.toString());   


}

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 .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Month {

private int Month;

private int MonthNumber;

private String Name;

public void setMonthNumber(int m) {

Month = m;

}

public int getMonthNumber() {

return Month;

}

public String getMonthName(int m) {

if (m == 1) {

Name = "January";

} else if (m == 2) {

Name = "Febuary";

} else if (m == 3) {

Name = "march";

} else if (m == 4) {

Name = "April";

} else if (m == 5) {

Name = "may";

} else if (m == 6) {

Name = "june";

} else if (m == 7) {

Name = "july";

} else if (m == 8) {

Name = "August";

} else if (m == 9) {

Name = "september";

} else if (m == 10) {

Name = "october";

} else if (m == 11) {

Name = "novermber";

} else if (m == 12) {

Name = "December";

}

return Name;

}

public boolean CorrectMonth() {

if (Month == 1) {

return true;

} else {

return false;

}

}

public static void main(String[] args) {

Month m = new Month();

System.out.println("The month is: " + m.getMonthName(1).toString());

}

}

======================================
SEE OUTPUT, Its compiling perfectly now




Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class named Month. The class should have an int field named monthNumber that holds...

    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...

  • 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 month...

    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:

    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...

  • All files require Javadoc documentation comments at the top to include a description of the program...

    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...

  • Create a simple Java class for a Month object with the following requirements:  This program...

    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,...

  • fisrt one is bicycle.java second code is bicycleapp.java can anyone help this??? please save my life...

    fisrt one is bicycle.java second code is bicycleapp.java can anyone help this??? please save my life Before you begin, DOWNLOAD the files “Lab8_Bicycle.java” and “Lab8_BicycleApp.java” from Canvas to your network drive (not the local hard drive or desktop). Once you have the files saved, RENAME THE FILES Bicycle.java and BicycleApp.java then open each file. 1) Look at the Bicycle class. Two of the many data properties we could use to define a bike are its color and the gear it...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

  • Comment your code. At the top of the program include your name, a brief description of...

    Comment your code. At the top of the program include your name, a brief description of the program and what it does and the due date. The program must be written in Java and submitted via D2L. The code matches the class diagram given above. The code uses Inheritance. In the following, you are given code for two classes: Coin and TestCoin. You study these classes first and try to understand the meaning of every line. You can cut and...

  • DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...

    DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to be DataSetEmployee. DataSetEmployee should extend ArrayList<Employee> and have no instance variables. You'll have to decide what replaces the getPages concept for getMax/getMin. As a hint, what method of Employee returns a numeric value? Make a package com.acme.midmanager. This package should contain the Manager class. Make a package com.acme.personnel. This package should contain the DataSetEmployee class. Make a package com.acme.topmanagement. This package should contain the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT