Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Infamous getAge() method help  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick question here.
I'm trying to create a variation of a getAge() method I created using Java 8's wonderful new library.
Here's what it looks like.


What I'm looking for help with is this code exactly:


It returns the age perfectly, but doesn't handle leap years very well, so I was just wondering if there was another way to re-create this getAge() method. Just as a note, in the main code, it prompts the user to enter their birth date (mm/dd/yyyy).
Thanks for the help.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kurumi,

Welcome to CodeRanch!

Kurumi Tokisaki wrote:but doesn't handle leap years very well


What does this mean exactly? Can you please provide and example.

Meanwhile, LocalDate class has isLeapYear method - which you may use to adjust code for leap year.

I hope this helps.

Thanks.
 
Kurumi Tokisaki
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for not being clear. That isLeapYear method will definitely help. Thanks for the tip. I was just wondering if the getAge() method I was using could be created another way in the Java 8 class. I've seen some examples online, but most of them are very long, or produced many errors...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!