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

/**
 * de persoon maken, hier word alles gemaakt wat 
 * docent en student gemeen hebben.
 */
import java.util.*;


public class Persoon
{
    /**
     *variabelen instantieren
     */
    private String naam;//voor methode setNaam
    private String geslacht;//voor methode setGeslacht
    private int leeftijd;   
    private int geboorteDag;
    private int geboorteMaand;
    private int geboorteJaar;
    private Calendar geboorteInformatie = new GregorianCalendar(); 

    /**
     * Constructor voor objecten van de class persoon
     */
    //eigenschappen van persoon construeren
    public Persoon(String naam, String geslacht, int geboorteDag, int geboorteMaand, int geboorteJaar )
    {
        this.naam = naam;
        this.geslacht = geslacht;
        this.geboorteDag = geboorteDag;
        this.geboorteMaand = geboorteMaand;
        this.geboorteJaar = geboorteJaar;
    }

    /**
     * methoden voor persoon
     */      
 
    //methode maken voor namen 
    public String setNaam(String voornaam, String achternaam)
    {
        naam = voornaam + " " + achternaam;
        return naam;
    }
    
    //methode maken voor het geslacht
    public String setGeslacht(String manOfVrouw)
    {
        geslacht = manOfVrouw;
        return geslacht;
    }
    
    //methode maken voor geboortedatum
    public void setGeboorteDatum(int geboorteDag, int geboorteMaand, int geboorteJaar)
    {
       geboorteInformatie.set(geboorteJaar,geboorteMaand,geboorteDag);
    }
    
    private int getGeboorteDag()
    {
        geboorteDag = geboorteInformatie.get(Calendar.DAY_OF_MONTH);
        return geboorteDag;
    }
    
    private int getGeboorteMaand()
    {
        geboorteMaand = geboorteInformatie.get(Calendar.MONTH);
        return geboorteMaand;
    }
    
    private int getGeboorteJaar()
    {
        geboorteJaar = geboorteInformatie.get(Calendar.YEAR);
        return geboorteJaar;
    }
    
    public void print()
    {
        System.out.println("Jaar: " + geboorteInformatie.get(Calendar.YEAR) +" Dag: "+ geboorteInformatie.get(Calendar.DAY_OF_MONTH)+" Maand: "+ geboorteInformatie.get(Calendar.MONTH));
        System.out.println("geslacht: " + geslacht); 
        System.out.println("Naam: " + naam);     
    }
    
    //checken welke persoon ouder is
    public boolean ouderDan(Persoon deAnder)
    {
        return geboorteInformatie.before(deAnder.geboorteInformatie);
        //als de geboorte van de eerste persoon eerder was dan de ander dan zal er true uitkomen 
          
    }
}

Recommended Answers

All 3 Replies

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.

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

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.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.