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

PLEASE ANSWER ALL 4 QUESTIONS JAVA PROGRAMMING 1. GIVEN THE CLASS BELOW, DESIGN

ID: 3609840 • Letter: P

Question

PLEASE ANSWER ALL 4 QUESTIONS JAVA PROGRAMMING
1. GIVEN THE CLASS BELOW, DESIGN THE METHOD "compareTo".

public class DateOfBirth
{
   private int year;
   private int month;
   private int date;

      :
      :

   public int compareTo (DateOfBirth theOther)
   {
      :
      :
   }


}



2. GIVEN THE CLASS BELOW, DESIGN THE METHOD "getAge",
WHICH CALCULATES AND RETUENS THE AGE OF A STUDENT AS OF
TODAY (03/23/2009).


public class Student
{
   private DateOfBirth dob;
   private String id;
   private double GPA;

     :
     :  

   public int getAge ( )
   {
     :
     :
   }


}




PLEASE ANSWER ALL 4 QUESTIONS JAVA PROGRAMMING
1. GIVEN THE CLASS BELOW, DESIGN THE METHOD "compareTo".

public class DateOfBirth
{
   private int year;
   private int month;
   private int date;

      :
      :

   public int compareTo (DateOfBirth theOther)
   {
      :
      :
   }


}



2. GIVEN THE CLASS BELOW, DESIGN THE METHOD "getAge",
WHICH CALCULATES AND RETUENS THE AGE OF A STUDENT AS OF
TODAY (03/23/2009).


public class Student
{
   private DateOfBirth dob;
   private String id;
   private double GPA;

     :
     :  

   public int getAge ( )
   {
     :
     :
   }


}




Explanation / Answer

public Integer getAge(Date onDate) {
if (birthdate == null)
return null;

Calendar today =Calendar.getInstance();
if (onDate != null)
today.setTime(onDate);

Calendar bday = newGregorianCalendar();
bday.setTime(birthdate);

int age = today.get(Calendar.YEAR) -bday.get(Calendar.YEAR);

//tricky bit:
// set birthday calendar to thisyear
// if the current date is less that thenew 'birthday', subtract
a year
bday.set(Calendar.YEAR,today.get(Calendar.YEAR));
if (today.before(bday))
age = age -1;

return age;
}

I hope this will helps you!!!!!!!!!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote