473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Enummeration/Loop help

I am needing help writing a program in which every month of the year is enumerated. It needs to run so that the user can input a day of the year in the format mm/dd/yyyy and the output be the day number in the year (the 3 of feb would be the 31 of jan plus 3 = 34), the date in the form dd/mmm/yyyy, and the year, and still being able to factor in leap years.

I'm just starting out in java and our teacher really hasn't taught us this stuff at all, and the book bites. Help would be greatly appreciated.
Oct 16 '06 #1
2 1486
I am needing help writing a program in which every month of the year is enumerated. It needs to run so that the user can input a day of the year in the format mm/dd/yyyy and the output be the day number in the year (the 3 of feb would be the 31 of jan plus 3 = 34), the date in the form dd/mmm/yyyy, and the year, and still being able to factor in leap years.

I'm just starting out in java and our teacher really hasn't taught us this stuff at all, and the book bites. Help would be greatly appreciated.

Maybe I can help u... I will try...
Oct 17 '06 #2
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.util.*;
  3. public class Dates {
  4.     public static void main (String[] args) {
  5.         String date = JOptionPane.showInputDialog("Date in the format dd/mm/yyyy: ");
  6.  
  7.         int year = Integer.parseInt(date.substring(6, 10));
  8.         int month = Integer.parseInt(date.substring(3, 5));
  9.         int day = Integer.parseInt(date.substring(0, 2));
  10.         GregorianCalendar a = new GregorianCalendar(year, month, day);
  11.         int[] days = new int[12];
  12.         for(int i = 0; i < 7;i++) {
  13.             if(i%2 == 0) {
  14.                 days[i] = 31;
  15.             }
  16.             else {
  17.                 days[i] = 30;
  18.             }
  19.         }
  20.         for(int i = 7; i < 12;i++) {
  21.             if(i%2 == 0) {
  22.                 days[i] = 30;
  23.             }
  24.             else {
  25.                 days[i] = 31;
  26.             }
  27.         }
  28.         if(isLeapYear(year)) {
  29.             days[1] = 29;
  30.         }
  31.         else {
  32.             days[1] = 28;
  33.         }
  34.         //finish it off
  35.  
  36.     }
  37.  
  38.     public boolean isLeapYear(int year) {
  39.         //write code to test for leap year here
  40.         return true;
  41.     }
  42. }
Oct 17 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Shill | last post by:
I have several questions. In C, AFAIU, a for loop is just syntactic sugar for a while loop. for (i1; i2; i3) i4; is equivalent to i1 while (i2) {
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
1
by: al2004 | last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for each team and prints the averages in a neatly formatted table along with the team name....
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
9
by: TF | last post by:
Hello all, I made a ASP.NET 2.0 site that shows possible "recipes" for paint colors stored in an access dbase. Basically, 1000 colors are stored with specific RGB values in separate columns. A...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
41
by: c | last post by:
Hi every one, Me and my Cousin were talking about C and C#, I love C and he loves C#..and were talking C is ...blah blah...C# is Blah Blah ...etc and then we decided to write a program that...
1
by: mshroom12 | last post by:
Hello to all. I am having difficulty trying to do this Java project using Eclipse. The following is what I have to do. Election Day It's almost election day and the election officials need a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.