Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make a program that reads a list of birthdays from a file called “birthdays.txt”

ID: 3843826 • Letter: M

Question

Make a program that reads a list of birthdays from a file called “birthdays.txt” (please make sure this name is exact). You will then ask the user to input a date and you are required to find: (1) who has the next birthday, (2) how many days away that birthday is from the input date and (3) how old the person will be on that birthday. (Note: you DO need to take into account leap year (see example 3)). The format of “birthdays.txt” will be: name_put_together_with_underscores : mm/dd/yyyy You may assume there is at least one birthday in “birthdays.txt”. You may also assume the date entered is valid. You do not need to check if the file opened correctly. birthdays.txt: Nick_Florin : 11/7/2000 David_Woodhouse : 8/12/1990 Michael_Smith : 11/13/1949 Mary_Rasmussen : 1/13/1987 Martin_Hughes : 3/13/1976 Melanie_Mouzon : 5/15/1933 Christine_Bonin : 2/10/1945 William_Holland : 6/13/1999 Doyle_Dye : 6/14/2014 Steve_Burkey_Frazier : 3/13/1972 Nell_Granberry : 4/25/1979 Madeleine_Daniel : 7/9/1968 Lillie_Callender : 6/16/1930 Shoshana_Falls : 5/27/1959 Example 1: Current date? 1/1/2040 Next birthday: Mary_Rasmussen in 12 days will turn 81 Example 2: Current date? 2/20/2017 Next birthday: Martin_Hughes in 21 days will turn 58 Example 3: Current date? 2/20/2016 Next birthday: Martin_Hughes in 22 days will turn 57

Explanation / Answer

BirthdaysFinding.java :
____________________

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner;


public class BirthdaysFinding {
   public static void main(String[] args) {
  
       try{
           Scanner sc = new Scanner(System.in);
           FileReader fr = new FileReader("F:\birthdays.txt");
           BufferedReader br = new BufferedReader(fr);
           System.out.println("Current date?");
           String dt = sc.next();
           String curent[] = dt.split("/");
           String line = null;
           int min = 999999,count = 0;
           StringBuffer sb = null;
           while((line = br.readLine())!=null){
               String det[] = line.split(":");
               String bday[] = det[1].split("/");
               int days =Math.abs(Integer.parseInt(curent[1]) - Integer.parseInt(bday[1]));
               int year =Math.abs(Integer.parseInt(curent[2]) - Integer.parseInt(bday[2]));
               int month =Math.abs(Integer.parseInt(curent[0]) - Integer.parseInt(bday[0]));
               count = days + (month *30);
               if(count<min){
                   sb = new StringBuffer();
                   sb.append("Next birthday:" +det[0]+" in "+count+" days will turn "+year);
                   min = count;
               }
       }
       System.out.println(sb);
       br.close();
       fr.close();
       }
       catch(Exception e){
           e.printStackTrace();
       }
   }
}

Sample Input and output:
______________________

Current date?
1/1/2040
Next birthday:Mary_Rasmussen in 12 days will turn 53

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote