Results 1 to 3 of 3
Thread: Define class and constructors
- 03-04-2010, 04:14 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
Define class and constructors
Ok this is gonna be a long one. I'm new with this java thing and i need to coma out with a program with the criteria below:
Define a class called Month. Your class will have one attribute of type int to
represent a month (1 for January, 2 for February, and so forth). Include all the
following methods in this class:
(a) a constructor to set the month using the first three letters in the name of
the month as three arguments (‘J’ ‘A’ ‘N’ for January, ‘F’ ‘E’ ‘B’ for
February, and so forth),
(b) a constructor to set the month using an integer as an argument (1 for
January, 2 for February, and so forth),
(c) a default constructor,
(d) an input function that reads the month as an integer,
(e) an input function that reads the month as the first three letters in the
name of the month,
(f) an output function that outputs the month as an integer,
(g) an output function that outputs the month as the first three letters in the
name of the month,
(h) and a member function that returns the next month as a value of type
Month.
Test your class in a new program which has the main() method.
I roughly know what to write at the beginning but my mind seem to be blank on how to write the conditions
public class months {
private int month;
public months()
{
month = months[m];
}
public months(String m)
{
}
public int MonthAsInt()
{
}
public String MonthAsString()
{
}
public months NextMonth()
{
}
public String toString()
{
}
}
Do i need a return statement? Really need some guidance on what needs to be done to complete this program.
- 03-04-2010, 04:31 PM #2
I don't see that anywhere.class called Month
I don't see that.(b) a constructor to set the month using an integer
And your skelleton code won't even compile as is. Don't try to do everyting at once. Start with b,c,d,f and get that running.Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-04-2010, 05:02 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think you should go through this first of all.
Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)
Similar Threads
-
define a variable
By jperson in forum New To JavaReplies: 2Last Post: 01-29-2010, 02:33 AM -
Define this error.
By jaicea in forum New To JavaReplies: 3Last Post: 12-02-2009, 01:07 AM -
How to define boolean in the fields ?
By racewithferrari in forum New To JavaReplies: 3Last Post: 11-26-2009, 06:01 PM -
[SOLVED] [newbie] getting the constructors of a class (java.lang.reflect)
By jon80 in forum New To JavaReplies: 1Last Post: 05-19-2009, 11:03 PM -
How to define a variable which can be accessed across the class?
By ajaykushwaha in forum New To JavaReplies: 3Last Post: 11-17-2008, 03:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks