Results 1 to 10 of 10
Thread: Help with Project
- 05-20-2012, 08:17 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Help with Project
I am working with this code:
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?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); } } }Last edited by Rahim2312; 05-20-2012 at 09:39 PM.
- 05-20-2012, 08:27 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Help with Project
A very nice indentation and totally consistent but not very readable ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-20-2012, 08:30 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Help with Project
When I pasted my code between the code tags it removed my indentions...
- 05-20-2012, 09:17 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Help with Project
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-20-2012, 09:20 PM #5
- 05-20-2012, 09:23 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
- 05-20-2012, 09:28 PM #7
- 05-20-2012, 09:30 PM #8
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
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).
- 05-20-2012, 09:38 PM #9
- 05-20-2012, 09:39 PM #10
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
How to transform a regular project to an EJB project?
By eildosa in forum EclipseReplies: 1Last Post: 05-17-2012, 09:43 PM -
Creating a project in eclipse from existing project
By Suraiya in forum New To JavaReplies: 1Last Post: 10-08-2011, 09:14 AM -
How to convert from Ant project to maven project?
By jiapei100 in forum New To JavaReplies: 0Last Post: 06-08-2011, 10:01 AM -
open existing project project ..
By itaipee in forum EclipseReplies: 1Last Post: 12-28-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks