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

Begin by prompting the user for today\'s date and for his/her birthday in month

ID: 3647608 • Letter: B

Question

Begin by prompting the user for today's date and for his/her birthday in month
day year format (see examples below).
Use this information to print the user's birthday in year/month/day format,
the day of the week the user was born, and how old the user is in days. If the
user was born in a leap year, you print an additional message letting them
know their birth year was a leap year.
Below are several example logs of execution from the program; user input is in
bold. Output is in italics. Your program's output should match these examples
exactly given the same input.
What is today's date (month day year)? 8 8 2010
What is your birthday (month day year)? 1 26 1971
You were born on 1971/1/26, which was a Tuesday.
You are 14439 days old.
What is today's date (month day year)? 8 8 2010
What is your birthday (month day year)? 2 2 1996
You were born on 1996/2/2, which was a Friday.
1996 was a leap year.
You are 5301 days old.
What is today's date (month day year)? 8 8 2010
What is your birthday (month day year)? 11 8 1900
You were born on 1900/11/8, which was a Thursday.
You are 40085 days old.
What is today's date (month day year)? 7 11 1856
What is your birthday (month day year)? 10 2 1800
You were born on 1800/10/2, which was a Thursday.
You are 20371 days old.
Solve this problem using Date objects. The methods and behavior of each Date
object are described on the next page.
To figure out the number of days old the user is, represent today and the
birthday as Date objects and use the methods found in the Date objects to
figure out how many days are between them. Note: Some of the methods
provided modify the state of the object on which they are called. See the next
page for method descriptions.
You can construct a Date object as follows:
Date name = new Date (year, month, day);
You do need to take leap years into account for this assignment. A leap year
occurs roughly every 4 years and adds a 29th day to February, making the year
366 days long. (Leap day babies usually celebrate their birthdays on February
28 or March 1 on non-leap years.) Date objects have various methods that can
help you to detect and handle the leap year case.
You may assume that neither today nor the user's birthday is the rare "leap
day" of February 29.
Assume valid input (that the user will always type a year between 1753

Explanation / Answer

please rate - thanks import java.util.*; public class DateClient {public static void main(String[] args) { int m,d,y; Scanner in=new Scanner(System.in); System.out.print("What is today's date (month day year)? "); m=in.nextInt(); d=in.nextInt(); y=in.nextInt(); Date today=new Date(m,d,y); System.out.print("What is your birthday (month day year)? "); m=in.nextInt(); d=in.nextInt(); y=in.nextInt(); Date bday=new Date(m,d,y); System.out.println("You were born on "+bday.toString()+", which was a "+bday.getDayofWeek()+"."); if(bday.leap(bday.getYear())==1) System.out.println( bday.getYear()+" was a leap year."); System.out.println("You are "+bday.daysAlive(today) +" days old."); } } ---------------------------------------------- public class Date {private int dMonth; //variable to store the month private int dDay; //variable to store the day private int dYear; //variable to store the year public Date() { } public Date(int m, int d, int y) {dMonth=m; dDay=d; dYear=y; } public int getMonth() {return dMonth; } public int getDay() {return dDay; } public int getYear() {return dYear; } public void setYear(int y) {dYear=y; } public String toString() {return (dYear + "/" + dMonth + "/" + dDay); } public int daysAlive(Date a) {int doy,doy2,days,j; doy=todoy(dMonth,dDay,dYear); //get day of year for 1st date doy2=todoy(a.dMonth,a.dDay,a.dYear); // get day of year for second date days=0; if(a.dYear-dYear==0) // same year? days=doy2-doy; else if(a.dYear-dYear==1) days=365+leap(dYear)-doy+doy2+days; // if 1 year apart get difference else {for(j=dYear+1;j1 year apart add 365 or 366 for each year days=days+365+leap(j); days=365+leap(dYear)-doy+doy2+days; } return days; } public int todoy(int month,int day,int year) {int daysinmonth; int days=0,i; for (i=1;i
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