how would I update the birthday I entered basically question 7 and 8 I have my o
ID: 3675979 • Letter: H
Question
how would I update the birthday I entered basically question 7 and 8I have my output also
I do I update birthday from 11,1,2016
to 8,3,1997
12Date%20(3). pdf 7) Prompt the user for the month, day and year of YOUR Scanner, as described above in (1) and using the variables the individual mutator (set) birthday this year. Print the date using whatever means you wish. birthday this year (B prompts) using (1) and using the variables declared in (e). Then, using all 3 of methods, update current date of mylday to the date of yous On what date number of the year (1-365 or 1-366) is your next birthday? Use the myBday date and getDateNum) to find the result, then print both your birthday AND this ordinal date together as a one-line Stringoutut 8) Using either date and its equals) method, check whether today is your birthday (compare the dates today and myBday). Assign the answer to the boolean variable result, print out the verdict. (If it is, Happy Birthday!) 9) Since all lava objects are ultimately descended from type Object, use the other CS12Date object for the input parameter Object obj. See the example code in C$12DateUsage java on Canvas for an example of this if needed. 10) Before proceeding, reset the following variables: month-0, days0, year-0. Then, using the 3 individual accessor (get) methods, reprint the date of your next birthday in mylday, Except print it in "dashes" form, MM-DD-YYYY, You will need to use string concatenation. Print the new date as a string using printin(). Note that you aren't "altering" the original my8day, you are just taking it apart using the accessors, and reassembling" it to create a new String, which you willthen print using System.out printing
Explanation / Answer
//Date.java
public class Date
{
private int day;
private int month;
private int year;
//Constructor to set dafault vlaue
public Date()
{
day=0;
month=0;
year=0;
}
//Create a constructor Date to set month, day and year
public Date(int month, int day, int year)
{
setDate(month, day, year);
}
//Set date
public void setDate(int month, int day, int year)
{
this.month=month;
this.day=day;
this.year=year;
}
//Setter methods for month, day and year
public void setMonth(int month)
{
this.month=month;
}
public void setDay(int day)
{
this.day=day;
}
public void setYear(int year)
{
this.year=year;
}
//Getter methods for month, day and year
public int getMonth()
{
return month;
}
public int getDay()
{
return day;
}
public int getYear()
{
return year;
}
/**The method getDateNum that returns the next year birht
* day on the day number as integer value*/
public int getDateNum()
{
//Set nextyear
int nextyear=year+1;
//set nextbirthday yo 0
int nextbirthday=0;
//find the number of days from 1 to month-1
for (int m = 1; m <=(month-1); m++)
nextbirthday=nextbirthday+getMonthDays(m);
//Add one additional day to leap year
if(isLeapYear(nextyear))
nextbirthday=nextbirthday+1;
//Add days to the nextbirthday
nextbirthday=nextbirthday+day;
//return nextbirthday
return nextbirthday;
}
/*Returns the number of days in given month*/
public int getMonthDays(int month)
{
int days=0;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 2:
days=28;
break;
case 4:
case 6:
case 9:
case 11:
days=30;
break;
}
return days;
}
/*Returns true if given is leap year or false*/
public boolean isLeapYear(int year)
{
return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
}
/**Returns the string representaion of Date object*/
@Override
public String toString() {
return "Date :"+month+"/"+day+"/"+year;
}
}
-------------------- -------------------- -------------------- --------------------
/*The java program TestDate that prompts user to enter month,
* day and year as input arguments and set month, day and year
* vlaues to the myBday object of Date class.
* The call getDateNum mtehod that returns the day on which
* next birthday will fall on next year.*/
//TestDate.java
import java.util.Scanner;
public class TestDate
{
public static void main(String[] args)
{
int day,month,year;
//Create a Scanner class object
Scanner scanner=new Scanner(System.in);
//Create an instance of Date class
Date myBday=new Date(11,1,2016);
System.out.println("Current birth date : "+myBday.toString());
//read month
System.out.println("Enter month :");
month=Integer.parseInt(scanner.nextLine());
//read day
System.out.println("Enter day :");
day=Integer.parseInt(scanner.nextLine());
//read year
System.out.println("Enter year :");
year=Integer.parseInt(scanner.nextLine());
//Call setMonth to set month
myBday.setMonth(month);
//Call setDay to set day
myBday.setDay(day);
//Call setYear to set year
myBday.setYear(year);
System.out.println("My Birhtday ");
System.out.println(myBday.toString());
//call getDateNum
int nextyeardate=myBday.getDateNum();
//String that represents date and nextyeardate
String birthDate=myBday+" Next year birhtday on day number "+nextyeardate;
//print the string
System.out.println(birthDate);
}
}
-------------------- -------------------- -------------------- --------------------
Sample output:
Current birth date : Date :11/1/2016
Enter month :
8
Enter day :
3
Enter year :
1997
My Birhtday
Date :8/3/1997
Date :8/3/1997 Next year birhtday on day number 215
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.