Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please help me to coding it (beginner)

  1. #1
    Junior Member
    Join Date
    May 2014
    Location
    KOTA KINABALU, SABAH
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Please help me to coding it (beginner)

    write a class named Month. the class have 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-argument constructor that sets the monthNUmber field to 1.
    - A construtor that accepts the number of the month as an argrument. 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 accept the name of the month, such as "January" or "February" as an argument. It should sat the monthNumber field to the correct corresponding value.
    - A setMonthNumber() menthod that accept int argument, which is assingned 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 return the value of the monthNUmber field.
    - A getMonthName() method that return thr name of the month.For example, if the monthNumber field contain 1, then this method should return "January".
    -A toString() method that return the same value as 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.
    -A greaterThan() that should accepts a Month object as an argument. if the calling object`s monthNumber field is greater than the argement monthNumber field. this method should return true. otherwise it should return false.
    - A lessThan() method that accept a Month object as an argument. if the calling object`s monthNumber field that the argument`s monthNumber field, this method should return true, otherwise it should return false.

    wtite exception class for the following error conditions :-
    - A number less than 1 or greater than 12 is given for the month number.
    - An invalid string return is given for the name of the month.

    modify the month class so that it throws the appropriate exception when either of these errors occurs. Demonstrate the classes in program.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please help me to coding it (beginner)

    Did you have any specific java programming problems?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Location
    KOTA KINABALU, SABAH
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me to coding it (beginner)

    Quote Originally Posted by Norm View Post
    Did you have any specific java programming problems?
    I don't know how I want to apply that exception into my coding... Can you show to me pal..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please help me to coding it (beginner)

    apply that exception
    Can you describe what you are asking about? I have not read your assignment.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help me with beginner coding
    By sandielee in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 29th, 2014, 10:18 PM
  2. Replies: 5
    Last Post: April 19th, 2013, 07:59 AM
  3. Need help with some coding
    By Firearrow5235 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: April 13th, 2013, 06:57 AM
  4. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  5. Need your help to coding
    By Tony_nguyen19 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 14th, 2011, 08:58 AM