will not remember calendar infor when inserted when creating class

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2008
Posts: 16
Reputation: Sereal_Killer is an unknown quantity at this point 
Solved Threads: 0
Sereal_Killer Sereal_Killer is offline Offline
Newbie Poster

will not remember calendar infor when inserted when creating class

 
0
  #1
Dec 13th, 2008
I have a basic problem i dont know where the error lies.
i can create a class Persoon and fill in all its values before its created .
but for some reason when i call up the information i get the current Date as the birthdate and not what i have entered.

when i enter the birtdate directly into the class via its method after it has been created it will rmember it.

the all the geboorte things are related to the birthDate tho you can probably see by the use of calendar

can anyone see why or tell me while?
maybe i dont understand the calendar api .
but we were forced to use calendar or date
Help with Code Tags

  1. /**
  2.  * de persoon maken, hier word alles gemaakt wat
  3.  * docent en student gemeen hebben.
  4.  */
  5. import java.util.*;
  6.  
  7.  
  8. public class Persoon
  9. {
  10. /**
  11.   *variabelen instantieren
  12.   */
  13. private String naam;//voor methode setNaam
  14. private String geslacht;//voor methode setGeslacht
  15. private int leeftijd;
  16. private int geboorteDag;
  17. private int geboorteMaand;
  18. private int geboorteJaar;
  19. private Calendar geboorteInformatie = new GregorianCalendar();
  20.  
  21. /**
  22.   * Constructor voor objecten van de class persoon
  23.   */
  24. //eigenschappen van persoon construeren
  25. public Persoon(String naam, String geslacht, int geboorteDag, int geboorteMaand, int geboorteJaar )
  26. {
  27. this.naam = naam;
  28. this.geslacht = geslacht;
  29. this.geboorteDag = geboorteDag;
  30. this.geboorteMaand = geboorteMaand;
  31. this.geboorteJaar = geboorteJaar;
  32. }
  33.  
  34. /**
  35.   * methoden voor persoon
  36.   */
  37.  
  38. //methode maken voor namen
  39. public String setNaam(String voornaam, String achternaam)
  40. {
  41. naam = voornaam + " " + achternaam;
  42. return naam;
  43. }
  44.  
  45. //methode maken voor het geslacht
  46. public String setGeslacht(String manOfVrouw)
  47. {
  48. geslacht = manOfVrouw;
  49. return geslacht;
  50. }
  51.  
  52. //methode maken voor geboortedatum
  53. public void setGeboorteDatum(int geboorteDag, int geboorteMaand, int geboorteJaar)
  54. {
  55. geboorteInformatie.set(geboorteJaar,geboorteMaand,geboorteDag);
  56. }
  57.  
  58. private int getGeboorteDag()
  59. {
  60. geboorteDag = geboorteInformatie.get(Calendar.DAY_OF_MONTH);
  61. return geboorteDag;
  62. }
  63.  
  64. private int getGeboorteMaand()
  65. {
  66. geboorteMaand = geboorteInformatie.get(Calendar.MONTH);
  67. return geboorteMaand;
  68. }
  69.  
  70. private int getGeboorteJaar()
  71. {
  72. geboorteJaar = geboorteInformatie.get(Calendar.YEAR);
  73. return geboorteJaar;
  74. }
  75.  
  76. public void print()
  77. {
  78. System.out.println("Jaar: " + geboorteInformatie.get(Calendar.YEAR) +" Dag: "+ geboorteInformatie.get(Calendar.DAY_OF_MONTH)+" Maand: "+ geboorteInformatie.get(Calendar.MONTH));
  79. System.out.println("geslacht: " + geslacht);
  80. System.out.println("Naam: " + naam);
  81. }
  82.  
  83. //checken welke persoon ouder is
  84. public boolean ouderDan(Persoon deAnder)
  85. {
  86. return geboorteInformatie.before(deAnder.geboorteInformatie);
  87. //als de geboorte van de eerste persoon eerder was dan de ander dan zal er true uitkomen
  88.  
  89. }
  90. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: will not remember calendar infor when inserted when creating class

 
0
  #2
Dec 13th, 2008
redundant info, delete
    private int geboorteDag;
    private int geboorteMaand;
    private int geboorteJaar;
use geboorteInformatie.get(XXX);

All the data are stored inside Calendar geboorteInformatie;
use constructor :
GregorianCalendar(int year, int month, int dayOfMonth)
Attention, from javadoc: Month value is 0-based. e.g., 0 for January
Make proper corrections to month value.
Last edited by quuba; Dec 13th, 2008 at 8:16 pm. Reason: correction
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 16
Reputation: Sereal_Killer is an unknown quantity at this point 
Solved Threads: 0
Sereal_Killer Sereal_Killer is offline Offline
Newbie Poster

Re: will not remember calendar infor when inserted when creating class

 
0
  #3
Dec 14th, 2008
so i dont need all the methods seperatly ?

im trying to understand but im not so good at java it appears .
anyway ill contininue to mess around with what you said and try and figure it out
thanks for the reply
Last edited by Sereal_Killer; Dec 14th, 2008 at 9:07 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 53
Reputation: neilcoffey will become famous soon enough neilcoffey will become famous soon enough 
Solved Threads: 6
neilcoffey neilcoffey is offline Offline
Junior Poster in Training

Re: will not remember calendar infor when inserted when creating class

 
0
  #4
Dec 14th, 2008
I think the way you're storing things is a little bit odd, and that's tying you in knots. You've declared variables that duplicate one another: on the one hand, you've got the separate 'day', 'month', 'year' variables. And on the other hand, you've got the Calendar.

Start by deciding on ONE way in which you're going to store the date of birth. If you're going to use a Calendar, then don't also have the separate ints, and vice versa. (I'd actually recommend a Date -- Calendar is really designed for calculating things with dates, but not storing an actual date.)

Then. once you've decided on your single way of storing a date, make sure that you always set this field consistently in all the places where you set a date. At the moment, your constructor does one thing, but your setGeboorteDatum() does another thing. (Once you've decided what setGeboorteDatum() will do, why not make your constructor call setGeboorteDatum() -- that way there's no risk of the two pieces of code accidentally evolving into different things later in time.)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC