Results 1 to 10 of 10
  1. #1
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Help with Project

    I am working with this code:
    Java Code:
    public class Date {
    
    private final int month;
    private final int day;
    private final int year;
    
    public Date(int m, int d, int y) {
    if (!increment(m, d, y))
    throw new RuntimeException("Invalid");
    month = m;
    day = d;
    year = y;
    }
    private static boolean increment(int m, int d, int y) {
    int[] DAYS = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    if (m < 1 || m > 12)
    return false;
    if (d < 1 || d > DAYS[m])
    return false;
    if (m == 2 && d == 29 && !isLeapYear(y))
    return false;
    return true;
    }
    private static boolean isLeapYear(int y) {
    if (y % 400 == 0)
    return true;
    if (y % 100 == 0)
    return false;
    return (y % 4 == 0);
    }
    public Date next() {
    if (increment(month, day + 1, year))
    return new Date(month, day + 1, year);
    else if (increment(month + 1, 1, year))
    return new Date(month + 1, 1, year);
    else
    return new Date(1, 1, year + 1);
    }
    public String toString() {
    return day + "-" + month + "-" + year;
    }
    public static void main(String[] args) {
    Date today = new Date(9, 30, 2010);
    System.out.println(today);
    for (int i = 0; i < 35; i++) {
    today = today.next();
    System.out.println(today);
    }
    }
    }
    What I can not figure out how to do is now create a separate file that will ask the user to input a month, a day and a year and asks the user how many days ahead to show. I know I will use JOptionPane.showInputDialog to ask for the user input, but how will I pass it back to the code to show the current day and then the entered number of days in advance to show?
    Last edited by Rahim2312; 05-20-2012 at 09:39 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help with Project

    A very nice indentation and totally consistent but not very readable ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with Project

    When I pasted my code between the code tags it removed my indentions...

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help with Project

    Quote Originally Posted by Rahim2312 View Post
    When I pasted my code between the code tags it removed my indentions...
    Strange; I copied thousands snippets of code, straight from an Eclipse editor or from vi, and never did this forum software remove my indentation; whether tabs or spaces ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Help with Project

    Quote Originally Posted by JosAH View Post
    I copied thousands snippets of code, straight from an Eclipse editor or from vi, and never did this forum software remove my indentation; whether tabs or spaces ...
    Ah, but you didn't copy form the floral subcontinent so-called tutorial site with the crappy codez, which is where this came from.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with Project

    Quote Originally Posted by DarrylBurke View Post
    Ah, but you didn't copy form the floral subcontinent so-called tutorial site with the crappy codez, which is where this came from.

    db
    Correct, I am working on a similar project, in my mind, I was thinking let me get the ins-and-out of exactly how this code runs from start-to-finish and then let me take what I learn and apply to my project.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Help with Project

    Quote Originally Posted by Rahim2312 View Post
    I have written this code:
    What made you wait 667 days to ask about something you posted as an answer to someone else's question on 23 July 2010?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with Project

    I did not post this answer. I was googling a to how to start my project (which I said is very similar) and came across that code. So I began working with that code to see exactly how it worked, but I am unable to get a piece of it figured out (and I will have to do the same thing in my code when I begin to write it).

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Help with Project

    In that case, why did you say this?
    Quote Originally Posted by Rahim2312 View Post
    I have written this code:
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with Project

    Force of habit. I will modify my original post.

Similar Threads

  1. Replies: 1
    Last Post: 05-17-2012, 09:43 PM
  2. Creating a project in eclipse from existing project
    By Suraiya in forum New To Java
    Replies: 1
    Last Post: 10-08-2011, 09:14 AM
  3. How to convert from Ant project to maven project?
    By jiapei100 in forum New To Java
    Replies: 0
    Last Post: 06-08-2011, 10:01 AM
  4. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •