Birthday Program in java

In this post, we will learn Birthday Program in java Programming language.


The digits on showroom wants to send offer messages to their customers on all days of the week. For example, if the day is Monday “The offer is 20% OFF”, if it is Tuesday “The offer is buy one get one”. Likewise, the showroom has come up with different offers for all 7 days. The showroom does not want to send these offers to all the customers though. If the customer’s birthday falls on a “Monday”, then the Monday offer will be forwarded to that customer. Help the showroom to find the day on which the customer’s birthday falls on.

Partial code to do the above task is already given.  In the Birthday class, a method called findDay will accept the date as argument and it should return the day, but if the date format is invalid then return “Invalid Date”.

 [The input is a date in the format “MM-dd-yyyy”, and the output will be the day]. The valid date format should be “MM-dd-yyyy”. Handle the exception, if the date is in a different format.

Sample Input and Output1:



Sample Input and Output2:


Invalid Date

Sample Input and Output2:


Invalid Date

Birthday Program in java CODE:

import java.util.Scanner;
 public class Main {
  public static void main(String[] args) {
 		Scanner sc=new Scanner(;
  	    //FILL CODE
 		Birthday a= new Birthday();

import java.util.Date;
import java.text.*;
public class Birthday {
   public String findDay(String date)
      //FILL CODE
      SimpleDateFormat sf = new SimpleDateFormat("MM-dd-yy");
       try {
           Date date1=sf.parse(date);
           sf=new SimpleDateFormat("EEEE");
           return sf.format(date1);
        } catch(ParseException e) {
           return "Invalid Date";
  1. Marathon Registration
  2. Array Manipulation – Use try with multi catch

Leave a Comment