The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Homework - Recompile with -Xlint:deprecation for details
Discuss Recompile with -Xlint:deprecation for details in the Java Help forum on Dev Shed. Recompile with -Xlint:deprecation for details Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 25th, 2012, 12:39 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 43 m 29 sec
Reputation Power: 0
|
|
|
Homework - 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;
}
}
|

October 25th, 2012, 01:38 PM
|
 |
Java Junkie
|
|
Join Date: Jan 2004
Location: Mobile, Alabama
|
|
|
The Date class is an older class. Many of it's methods are deprecated.
|

October 25th, 2012, 01:47 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 43 m 29 sec
Reputation Power: 0
|
|
Quote: | 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?
|

October 25th, 2012, 01:49 PM
|
 |
Java Junkie
|
|
Join Date: Jan 2004
Location: Mobile, Alabama
|
|
Quote: | 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.
|

October 25th, 2012, 05:08 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 43 m 29 sec
Reputation Power: 0
|
|
|
Perfect...Thanks for your help
|

October 25th, 2012, 06:06 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 43 m 29 sec
Reputation Power: 0
|
|
How would you rewrite the getAge...Ive tried every way I know of and I'm getting errors across the board 
|

October 26th, 2012, 08:14 AM
|
 |
Java Junkie
|
|
Join Date: Jan 2004
Location: Mobile, Alabama
|
|
Quote: | 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|