View Single Post
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

Help with java calendar

 
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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  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. }
Last edited by Sereal_Killer; Dec 13th, 2008 at 5:33 pm. Reason: added code cause i forgot
Reply With Quote