| | |
Actual Date to Day of the Week Application
![]() |
I have been using JAVA for a whole two weeks now. I am enrolled in CSC 148 at my local college.
I am supposed to write a program that asks the user for his or her age and replies with the day of the week on which he or she was born.
I am familiar with the I/O, but cannot figure out to convert from a date
(ie. 07/04/1776) to a day (ie. Saturday).
Here is my current code:
/*
Ask the user for his or her birthdate and return with the day of the week
on which he or she was born.
*/
import javax.swing.*;
import java.sql.*; //For Return Date
class Exercise2_29 {
public static void main( String[] args ) {
//Input user birth date
String bdate;
bdate = JOptionPane.showInputDialog(null, "What is your birth date?
(MM/DD/YYYY)");
//Convert user birth date to day of week
}
}
Note: I can only use the java.util or java.sql classes. The GregorianCalendar class has not yet been officially taught and, therefore, can't be used.
Also, is the code I currently have good. Do I need to import any other classes, or add any more strings?
Thanks in advance for any help.
bcheath_1
I am supposed to write a program that asks the user for his or her age and replies with the day of the week on which he or she was born.
I am familiar with the I/O, but cannot figure out to convert from a date
(ie. 07/04/1776) to a day (ie. Saturday).
Here is my current code:
/*
Ask the user for his or her birthdate and return with the day of the week
on which he or she was born.
*/
import javax.swing.*;
import java.sql.*; //For Return Date
class Exercise2_29 {
public static void main( String[] args ) {
//Input user birth date
String bdate;
bdate = JOptionPane.showInputDialog(null, "What is your birth date?
(MM/DD/YYYY)");
//Convert user birth date to day of week
}
}
Note: I can only use the java.util or java.sql classes. The GregorianCalendar class has not yet been officially taught and, therefore, can't be used.
Also, is the code I currently have good. Do I need to import any other classes, or add any more strings?
Thanks in advance for any help.
bcheath_1
I'm a newbie, also, trying to figure out the same problem...and I'm still trying to figure out just how to use DateFormat, SimpleDateFormat, java.util.Date, and Calendar. It seems that the original post was trying to get an example of how you programatically determine the day of the week that a person was born on...Could someone provide a basic example of this?
Thanks,
Thanks,
nah. Plug the date into a Calendar and get the correct field out of it...
Something like
The biggest mistake many beginners in Java (or most languages) seem to make is to not study the standard library.
It contains a TON of very handy utility classes that can really make your life easy.
Something like
Java Syntax (Toggle Plain Text)
Calendar calendar = new GregorianCalendar(); calendar.setTime(birthdate); int dayOfBirth = calendar.get(Calendar.DAY_OF_WEEK);
The biggest mistake many beginners in Java (or most languages) seem to make is to not study the standard library.
It contains a TON of very handy utility classes that can really make your life easy.
![]() |
Similar Threads
- date to day of the week (Python)
- Code Snippet: Calculate day of the week for a given date MM-DD-YYYY (Perl)
- Day of Week (Python)
- Logic to Convert Days From 1800 to a Date (Month, Day, Year) (C++)
Other Threads in the Java Forum
- Previous Thread: Help with a Calendar!!
- Next Thread: sms via java
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows






