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 3 of 3

Thread: Bracket placement issues

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    18
    My Mood
    Stressed
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Bracket placement issues

    My code isn't running and I know I have brackets in the wrong places.

     import java.util.Calendar;
     
    public class Date {
     
    private int month;
    private int day;
    private int year;
     
    public static void main(String[] args) {
    public Date( int theMonth, int theDay, int theYear )
    {
    month = checkMonth( theMonth );
    year = checkYear( theYear );
    day = checkDay( theDay );
    System.out.printf(
    "Date object constructor for date %s\n", toString() );
    }
    private int checkYear( int testYear )
    {
    if ( testYear > 0 )
    return testYear;
    else 
    {
    System.out.printf(
    "Invalid year (%d) set to 1.\n", testYear );
    return 1;
    }
    }
    private int checkMonth( int testMonth )
    {
    if ( testMonth > 0 && testMonth <= 12 )
    return testMonth;
    else 
    {
    System.out.printf(
    "Invalid month (%d) set to 1.\n", testMonth );
    return 1;
    }
    }
    private int checkDay( int testDay )
    {
    int daysPerMonth[] =
     
    { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
     
    if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
    return testDay;
    if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
    ( year % 4 == 0 && year % 100 != 0 ) ) )
    return testDay;
     
    System.out.printf( "Invalid day (%d) set to 1.\n", testDay );
    return 1;
    }
    public void nextDay()
    {
    int testDay = day + 1;
     
    if ( checkDay( testDay ) == testDay )
    day = testDay;
    else
    {
    day = 1;
    nextMonth();
    }
    }
    public void nextMonth()
    {
    if ( 12 == month )
    year++;
     
    month = month % 12 + 1;
    }
    public String toString()
    {
    return String.format( "%d/%d/%d", month, day, year );
    }
    }
    }
    class DateTest
    {
    public static void main( String args[] )
    {
    System.out.println( "Checking increment" );
    Date testDate = new Date( 03, 13, 2011 );
     
    for ( int counter = 0; counter < 3; counter++ )
    {
    testDate.nextDay();
    System.out.printf( "Incremented Date: %s\n",
    testDate.toString() );
    }
    }
    }


  2. #2
    Junior Member
    Join Date
    Mar 2011
    Posts
    18
    My Mood
    Stressed
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Bracket placement issues

    I figured it out.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Bracket placement issues

    There looks like there are quite a few errors in your code including a misplaced constructor.
    I'm glad you have figured it out.. Let us know if you need anything else.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. JLabel placement issues
    By fride360 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 11th, 2011, 12:20 PM
  2. Alignment issues
    By fride360 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 10th, 2011, 01:58 PM
  3. Variable declaration placement
    By 2nickpick in forum Java Theory & Questions
    Replies: 2
    Last Post: January 22nd, 2011, 10:34 AM
  4. Placement of code within an application
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 12th, 2010, 07:26 PM
  5. Having Issues Past this
    By baGoGoodies111 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2009, 07:19 PM