A class named Month

program tests the month class

Page 1 of 1

6 Replies - 10962 Views - Last Post: 17 April 2009 - 04:24 PM Rate Topic: -----

#1 SovbodMark   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 31-March 09

A class named Month

Post icon  Posted 16 April 2009 - 08:26 PM

I have a problem with this program. It confused me a lot . Any ideas?
import java.util.Calendar;
 
public class GetMonth
{
	public static void main(String[] args)
	{
		String[] months = {"January", "February",
			"March", "April", "May", "June", "July",
			"August", "September", "October", "November",
			"December"};
 
		Calendar cal = Calendar.getInstance(); 
		String month = months[cal.get(Calendar.MONTH)];
		System.out.println("Month name: " + month);
	}
} 



Is This A Good Question/Topic? 0
  • +

Replies To: A class named Month

#2 DavidDD   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-April 09

Re: A class named Month

Posted 16 April 2009 - 10:25 PM

I have the same problem, I hope they help you


View PostSovbodMark, on 16 Apr, 2009 - 07:26 PM, said:

I have a problem with this program. It confused me a lot . Any ideas?
import java.util.Calendar;
 
public class GetMonth
{
	public static void main(String[] args)
	{
		String[] months = {"January", "February",
			"March", "April", "May", "June", "July",
			"August", "September", "October", "November",
			"December"};
 
		Calendar cal = Calendar.getInstance(); 
		String month = months[cal.get(Calendar.MONTH)];
		System.out.println("Month name: " + month);
	}
} 


Was This Post Helpful? 0
  • +
  • -

#3 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: A class named Month

Posted 16 April 2009 - 10:51 PM

You say you have the same "problem"
Erm.. he never stated a problem, nor an error, or what he is trying to do with the code. We can't help if we don't know what your needing help with.

This post has been edited by Fuzzyness: 16 April 2009 - 10:51 PM

Was This Post Helpful? 0
  • +
  • -

#4 DavidDD   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-April 09

Re: A class named Month

Posted 16 April 2009 - 11:42 PM

As for me, my problem is I have no idea how to use the following methods in this program:

-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 have the value passed as the argument.
- A constructor that accepts the name of the month, such as "January" or "February" as an argument.
-A setMonthNumber method that accepts an int argument. If a value less than 1 or greater than 12 is passes, the
method should set monthNumber to 1.
- A getMonthNumber method.
-A getMonthName.
- A toString method.
An equals method.
A greaterThan method
A lessThan metod

import java.util.Calendar;

public class GetMonth
{
	public static void main(String[] args)
	{
		String[] months = {"January", "February",
			"March", "April", "May", "June", "July",
			"August", "September", "October", "November",
			"December"};

		Calendar cal = Calendar.getInstance(); 
		String month = months[cal.get(Calendar.MONTH)];
		System.out.println("Month name: " + month);
	}
} 


Was This Post Helpful? 0
  • +
  • -

#5 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7197
  • View blog
  • Posts: 15,004
  • Joined: 16-October 07

Re: A class named Month

Posted 17 April 2009 - 04:41 AM

View PostDavidDD, on 17 Apr, 2009 - 12:42 AM, said:

As for me, my problem is I have no idea how to use the following methods in this program:


You've already had the entire thing described to you! Just fill in the blanks.

This should get you started. Now, show some effort! :P

import java.util.Calendar;

public class MyMonth {
	private int monthNum;
	private final String[] months = {"January", "February",
			"March", "April", "May", "June", "July",
			"August", "September", "October", "November",
			"December"};
	
	// -A no-arg constructor that sets the monthNumber field to 1
	public MyMonth() { /* your code here */ }

	//-  A constructor that accepts the name of the month, such as "January" or "February" as an argument.
	public MyMonth(int monthNum) { /* your code here */ }
	
	// -A setMonthNumber method that accepts an int argument. If a value less than 1 or greater than 12 is passes, the method should set monthNumber to 1.
	
	public void setMonthNumber(int monthNum) { /* your code here */ }
	
	//- A getMonthNumber method.
	public int getMonthNumber() { /* your code here */ }

	// -A getMonthName.
	public String getMonthName() { return months[getMonthNumber()-1]; }

	// - A toString method.
	public String toString() { /* your code here */ }

	// An equals method.
	public boolean equals(Object other) { /* your code here */ }
	
	//A greaterThan method 
	public boolean greaterThan(MyMonth other) { /* your code here */ }

	//A lessThan metod
	public boolean lessThan(MyMonth other) { /* your code here */ }
	
	
	public static void main(String[] args) {
		Calendar cal = Calendar.getInstance(); 
		MyMonth mon = new MyMonth(cal.get(Calendar.MONTH));
		System.out.println("Month name: " + mon.getMonthName());
	}
} 


Was This Post Helpful? 0
  • +
  • -

#6 DavidDD   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-April 09

Re: A class named Month

Posted 17 April 2009 - 04:09 PM

how can I find thses codes which you wanted me to write
[quote name='baavgai' date='17 Apr, 2009 - 03:41 AM' post='609332']
[quote name='DavidDD' post='609179' date='17 Apr, 2009 - 12:42 AM']
As for me, my problem is I have no idea how to use the following methods in this program:
[/quote]

You've already had the entire thing described to you!  Just fill in the blanks.

This should get you started.  Now, show some effort! :P

[code=java]
import java.util.Calendar;

public class MyMonth {
	private int monthNum;
	private final String[] months = {"January", "February",
			"March", "April", "May", "June", "July",
			"August", "September", "October", "November",
			"December"};
	
	// -A no-arg constructor that sets the monthNumber field to 1
	public MyMonth() { /* your code here */ }

	//-  A constructor that accepts the name of the month, such as "January" or "February" as an argument.
	public MyMonth(int monthNum) { /* your code here */ }
	
	// -A setMonthNumber method that accepts an int argument. If a value less than 1 or greater than 12 is passes, the method should set monthNumber to 1.
	
	public void setMonthNumber(int monthNum) { /* your code here */ }
	
	//- A getMonthNumber method.
	public int getMonthNumber() { /* your code here */ }

	// -A getMonthName.
	public String getMonthName() { return months[getMonthNumber()-1]; }

	// - A toString method.
	public String toString() { /* your code here */ }

	// An equals method.
	public boolean equals(Object other) { /* your code here */ }
	
	//A greaterThan method 
	public boolean greaterThan(MyMonth other) { /* your code here */ }

	//A lessThan metod
	public boolean lessThan(MyMonth other) { /* your code here */ }
	
	
	public static void main(String[] args) {
		Calendar cal = Calendar.getInstance(); 
		MyMonth mon = new MyMonth(cal.get(Calendar.MONTH));
		System.out.println("Month name: " + mon.getMonthName());
	}
} 


Was This Post Helpful? 0
  • +
  • -

#7 Locke   User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 550
  • View blog
  • Posts: 5,624
  • Joined: 20-March 08

Re: A class named Month

Posted 17 April 2009 - 04:24 PM

View PostDavidDD, on 17 Apr, 2009 - 05:09 PM, said:

how can I find thses codes which you wanted me to write


You don't want to find them...you want to write them. The assignment is very straightforward, and we haven't seen any effort.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1