-3
public class Person
private final Date  birthDate;
// others fields omitted
public  boolean isBabyBoomer() {
Calendar gmtCal =
Calendar.getInstance(TimeZone.getTimeZone("GMT"));
gmtCal.set(1946,Calendar.JANUARY,1,0,0,0);
Date boomStart =gmtCal.getTime();
gmtCal.set(1965,Calendar.JANUARY,1,0,0,0);
Date boomEnd = gmtCal.getTime();
return birthDate.compareTo(boomStart) >= 0 &&   //where is Birthdate instance 
                                                 // to compare                                   
birthDate.compareTo(boomEnd) < 0;

}
}
  1. when and how the program gets birthdate instance ?
  2. Do they omitted coding process for that instance ?
  3. For what purpose they compared results with zero(>= and < ) inside return ?
  4. Can not we use simple return without using zeros integer (boolean only for testing) ?
Kevyn Meganck
  • 609
  • 6
  • 15
karthick
  • 68
  • 1
  • 6
  • 1
    The book assumes you can work these things out for yourself, so I suggest you try doing just that. You can answer these questions without any additional information, there is no trick here. – Peter Lawrey Mar 07 '16 at 09:46
  • A trickier question would be; proposes a different date for the `boomStart` and say why this might be better than using Jan 1st. – Peter Lawrey Mar 07 '16 at 09:47
  • thank you peter ,can we write return as return birthDate.compareTo(boomStart) && birthDate.compareTo(boomEnd) ; without knowing how to set birthdate it is hard for me to test(compile) .Anyone help to by writing the full code to get birthDate thank you – karthick Mar 07 '16 at 12:35
  • See [this question](https://stackoverflow.com/q/3767090/113632) for a discussion of the `compareTo()` API. – dimo414 Jul 23 '17 at 00:34

1 Answers1

0
  1. Given fact birthDate is final, i would say it is passed to class via constructor,

  2. It is common practice in books and other tutorin materials to omit bits of code which are not relevant for given example to avoid creating extra confision for reader

  3. Method compareTo returns int hence if you want to convert this to boolean result, you have to compare it to some number by using one of of the operators ==, !=, <, >, <=, >=

  4. And how you want to use simple return?

user902383
  • 8,420
  • 8
  • 43
  • 63