ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 27 Apr 2017 My Price 11.00

public class BirthdayMonthyearjava

I have problem with the birthday and also the teacher needs teacherdate

 

 

import java.util.*;
public class BirthdayMonthyearjava { public static class Birthday{
public static void main (Stringargs ){
//Asks for year, month, and day born, enter for example by
typing year # then press enter
//repeat that for month # and day #.
Scanner input = new Scanner(System.in);
System.out.print("What year, month, and day were you born?");
int month = input.nextInt();
int day = input.nextInt();
int year = input.nextInt();
//Obtaining objects from TeacherDate class and creating
variables for them
TeacherDate date = new TeacherDate(month, day, year);
TeacherDate today = new TeacherDate();
//Print out the day that user was born on.
System.out.println("You were born on " + date.toString() + ",
which was a " + date.getDayOfWeek() + ".");
//Birthday message
if (date.getDay() == today.getDay() && date.getMonth() ==
today.getMonth()){
System.out.println("Happy Birthday! You are now age " +
getAge(date, today));
}
//Leap Year message.
else if (date.isLeapYear()){
System.out.println(date.getYear() + " was a leap
year.");
}
//Prints days until birthday.
if (dayCounter(date, today) != 365){
System.out.println("It will be your birthday in " +
daysUntilBirthday(date, today) + " days.");
}
//How many days old the person is.
System.out.println("You are " + dayCounter(date, today) + "
days old.");
}
//Finds age
public static int getAge( TeacherDate date, TeacherDate today ){
return (today.getYear() - date.getYear());
}//End of method getAge
//Solves days between dates
public static int dayCounter(TeacherDate date, TeacherDate today){
double daysOld = 0;
TeacherDate dayCounter = new TeacherDate(date.getYear(),
date.getMonth(), date.getDay());
while (dayCounter.equals(today) == false) {
++daysOld;
dayCounter.nextDay(); }
} today){ return (int) daysOld; //Finds how many days until birthday
public static int daysUntilBirthday(TeacherDate date, TeacherDate TeacherDate birthday = new TeacherDate(today.getYear(),
date.getMonth(), date.getDay());
TeacherDate birthdayAfter = new TeacherDate((today.getYear() +
1), date.getMonth(), date.getDay());
//If the birthday has not happened in the current year
if( birthday.getMonth()<= today.getMonth()&&birthday.getDay()
< today.getDay()){
return dayCounter(birthday, today);
}
//If the birthday is later in the year, but hasn't happened.
else if (birthday.getMonth() > today.getMonth()){
return dayCounter(today, birthday);
}
//If the closest birthday is next year.
else{
return dayCounter(today, birthdayAfter);
}
}
}
}

Answers

(11)
Status NEW Posted 27 Apr 2017 02:04 AM My Price 11.00

-----------

Not Rated(0)