#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Recompile with -Xlint:deprecation for details


    Full error: Example4.java uses or overrides a deprecated API. Recompile with -Xlint:deprecation for details.

    I'm not sure why I'm getting this and I still have to do the rest of my printouts but wanted to figure this out first. I've also heard these are just warnings and don't worry about them but I'm not able to test my code to make sure everything is in working order.

    import java.util.Date;

    public class Example4 {
    public static void main(String[] args) {

    Buck buck1 = new Buck();


    System.out.printf("Buck 1 %s years old");


    Buck buck2 = new Buck("10/14/2001", 200.0, 68.0, 6, 2);


    }
    }

    class Buck {


    private Date bdate;
    private double weight;
    private double height;
    private int points;
    private int horns;


    Buck() {
    this.bdate = new Date("11/02/2000");
    this.weight = 205.5;
    this.height = 63.0;
    this.points = 10;
    this.horns = 2;
    }

    Buck(String bdateIn, double weightIn, double heightIn, int pointsIn, int hornsIn) {
    this.bdate = new Date();
    this.weight = weightIn;
    this.height = heightIn;
    this.points = pointsIn;
    this.horns = hornsIn;
    }

    public Date getBdate() {
    return bdate;
    }
    public double getWeight() {
    return weight;
    }
    public double getHeight() {
    return height;
    }
    public int getPoints() {
    return points;
    }
    public int getHorns() {
    return horns;
    }


    public int getAge() {
    Date now = new Date();
    int nowMonth = now.getMonth();
    int nowYear = now.getYear();
    int bdateMonth = bdate.getDate();
    int bdateYear = bdate.getYear();

    return (nowMonth >= bdateMonth ? nowYear - bdateYear:nowYear - bdateYear - 1);
    }

    double getmetricWeight(){
    return weight / 2.2;
    }
    double getfeet(){
    return height / 12;
    }
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    The Date class is an older class. Many of it's methods are deprecated.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by bullet
    The Date class is an older class. Many of it's methods are deprecated.
    So I need to fix it with an updated class to fix this I'm assuming?
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Originally Posted by Falkin
    So I need to fix it with an updated class to fix this I'm assuming?
    That's right. The recommended class is Calendar. For printing out, there is DateFormat.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    Perfect...Thanks for your help
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    How would you rewrite the getAge...Ive tried every way I know of and I'm getting errors across the board
  12. #7
  13. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Originally Posted by Falkin
    How would you rewrite the getAge...Ive tried every way I know of and I'm getting errors across the board
    You can create an instance of a Calendar with the static method getInstance(). There are several predefined constants in the Calendar class. In particular, there is Calendar.MONTH, Calendar.DAY_OF_MONTH, etc. If you look at the docs for Calendar.java you will see all of them. You can get a particular piece of information with the get method.

IMN logo majestic logo threadwatch logo seochat tools logo