0

okay so I'm trying to create a program in which a user with input their day of birth in the dd/mm/yyyy format (or something similar). My teacher and I have a hard time connecting, mostly due to my hectic schedule so she can't always help. I'll post the assignment instructions but keep in mind, if you would like tohelp me, I'm very VERY slow at picking this up. So "idiot" instructions are preferred :-)...'Here is the specific instructions....how do I even start this?

***Write a program that asks the user fire his/her birth date and replies with the day of the week on which they were born. You CANNOT use the Gregorian Calendar for this.

There are hints to use both java.util and java.sql and that the string representation must be in the yyyy-MM-dd format.

If more info on my end is needed, let me know. I want SO badly to understand this, since it is my major.

Here's what i've started. I apologize if its WAAY off....(this is the 3rd version :-))

    String date, month, day, year;
    Scanner input = new Scanner(System.in);
    Date birthday = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("EEEE");



    System.out.println("Please enter your date of birth as mm/dd/yyyy");
    date = input.next();

    birthday = java.sql.Date.valueOf(date);

    System.out.println("You were born on a " + sdf.format(date));

Thanks to all!!

kandaspohn
  • 89
  • 1
  • 12

2 Answers2

0

Hint LocalDate.getDateOfWeek().

NiematojakTomasz
  • 2,433
  • 20
  • 23
0

The problem resolved in (back to my CNAM courses) :

Zeller.c :

#include <stdio.h>
#include <iostream>
using namespace std;
#define IVLD "Date pour Zeller invalide\n"
#define TRUE 1

// passage des parametres de la fonction() par valeurs
int Zeller(int day, int month, int year) {

    int dayOfWeek, adjustedMonth, yearInCentury, century;

    /* verification date mini "15 Octobre 1582" + jour, mois, annee valid */
    if ((day < 1 || day > 31) || (year < 1582) || (year == 1582 && month < 10) || (year == 1582 && month == 10 && day < 15)) {
        cout << IVLD;
        return 255;
    }

    yearInCentury = year % 100; century = year / 100;

    /* ajustage de la date pour que
     * Mars soit le mois 1 et fevrier le 12 */
    adjustedMonth = month - 2;
    if (adjustedMonth <= 0) {
        adjustedMonth += 12;
        --yearInCentury;
    }

    /* Congruence de Zeller
       Annum civilem necessario constare ex diebus integris ! (Christophorus Clavius 1537 - 1612) */
    dayOfWeek = ( ((int) (2.6 * adjustedMonth - 0.2) + day + yearInCentury + (int) (yearInCentury / 4) + (int) (century / 4) - 2 * century) % 7);

    switch(dayOfWeek) {
        case 0: cout << "dimanche\n";   break;
        case 1: cout << "lundi\n";      break;
        case 2: cout << "mardi\n";      break;
        case 3: cout << "mercredi\n";   break;
        case 4: cout << "jeudi\n";      break;
        case 5: cout << "vendredi\n";   break;
        case 6: cout << "samedi\n";     break;
        default: cout << "Calcul errone, merci de remonter le bug aupres du developpeur SVP\n"; return(255);
    }

    return(dayOfWeek);
}

The algorithm can be easily ported in java =)

Sorry for the french noise (but the main code in in English).

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223