Actual Date to Day of the Week Application

Reply

Join Date: Jan 2005
Posts: 20
Reputation: bcheath_1 is an unknown quantity at this point 
Solved Threads: 1
bcheath_1's Avatar
bcheath_1 bcheath_1 is offline Offline
Newbie Poster

Actual Date to Day of the Week Application

 
0
  #1
Jan 22nd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Actual Date to Day of the Week Application

 
0
  #2
Jan 23rd, 2005
install the API docs.
Look up DateFormat, SimpleDateFormat, java.util.Date, and Calendar.
Using those you can do what you want quite easily.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1
Reputation: rachawal is an unknown quantity at this point 
Solved Threads: 0
rachawal's Avatar
rachawal rachawal is offline Offline
Newbie Poster

Re: Actual Date to Day of the Week Application

 
0
  #3
Feb 1st, 2005
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,
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 46
Reputation: Gink is an unknown quantity at this point 
Solved Threads: 0
Gink Gink is offline Offline
Light Poster

Re: Actual Date to Day of the Week Application

 
0
  #4
Feb 1st, 2005
count the days in between current date and that date, subtract it, mod it by 7
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Actual Date to Day of the Week Application

 
0
  #5
Feb 2nd, 2005
nah. Plug the date into a Calendar and get the correct field out of it...
Something like
  1. Calendar calendar = new GregorianCalendar();
  2. calendar.setTime(birthdate);
  3. 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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC