Java Reference
In-Depth Information
< Day Day Up >
Puzzle 49: Larger Than Life
Lest you think that this topic is going entirely to the dogs, this puzzle concerns royalty. If the
tabloids are to be believed, the King of Rock 'n' Roll is still alive. Not one of his many
impersonators but the one true Elvis. This program estimates his current belt size by projecting the
trend observed during his public performances. The program uses the idiom
Calendar.getInstance().get(Calendar.YEAR) , which returns the current calendar year. What
does the program print?
public class Elvis {
public static final Elvis INSTANCE = new Elvis();
private final int beltSize;
private static final int CURRENT_YEAR =
Calendar.getInstance().get(Calendar.YEAR);
private Elvis() {
beltSize = CURRENT_YEAR - 1930;
}
public int beltSize() {
return beltSize;
}
public static void main(String[] args) {
System.out.println("Elvis wears a size " +
INSTANCE.beltSize() + " belt.");
}
}
 
 
Search WWH ::




Custom Search