Date Class Practice
Make a class Date
that has three instance fields (variables) for storing the year, month and day. Make at least two constructors, and two methods. One method should be called getAge
and returns an int
which is the years since the last birthday, and another called getPreciseAge
that returns a String
that returns the age in terms of years, months and days.
DateTester.java
public class DateTester { public static void main(String[] args) { Date gabrielsbday=new Date(1998,8,11); Date fcsbday=new Date(1960,10,30); Date today= new Date(2015,9,30); System.out.println(gabrielsbday.getAge(today)); System.out.println(fcsbday.getAge(today)); } }