Object Oriented Programming-creating new objects

Posted 08 August 2012 - 12:05 PM

I just started learning about object oriented programming. The program is supposed to ask the user for today's date and his birthday in (monday day year) format. It will than print the birthday (year/month/day), the day of the week the user was born, and how old he is in days. The assignment tells us what methods to implement in the data.java file as well as what the method should do.
I already wrote all the methods except I'm having a problem with public int advanceTo(Date endDay) which modifies the state of this Date object by advancing it to the given end Date and returns the number of days it took to advance this Date object to the given end Date. I'm guessing public boolean equals(Date d) is also incorrect as I think it should compare a complete date not just the day.
Anyways, my question comes from the Dataclient.java file (the 2nd pice of code here). I'm trying to create a new object from the input provided by the user but once it runs the "new Date" line, it runs an object with 0/0/0. Can someone explain to me what I did wrong or what I'm missing?

import java.util.*;
public class DateClient {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
giveIntro();
System.out.print("What is today's date (month day year)? ");
int month = console.nextInt();
int day = console.nextInt();
int year = console.nextInt();
Date today = new Date(year, month, day);
System.out.print("What is your birthday (month day year)? ");
month = console.nextInt();
day = console.nextInt();
year = console.nextInt();
Date birthday = new Date(year, month, day);
System.out.println(birthday);
System.out.print("You were born on " + birthday);
System.out.println(", which was a " + today.getDayOfWeek() + ".");
System.out.println("You are " + birthday.advanceTo(today) + " days old.");//how to call this method??
}
public static void giveIntro() {
System.out.println("This program tells you what day of the week you were born on,");
System.out.println("how old you are in days, and if you were born on a leap year.");
System.out.println();
}
}

when you have a boolean method always easier to exit as soon as a condition is not encountered

//returns whether this Date's year is a leap year
public boolean isLeapYear() {
if(year%4 != 0)
return false;
.....
}

Nice catch! Thanks for pointing it out.
I'm having a hard time trying to build a new object in the advanceTo() method using the birthday as the date. Could someone point me in the right direction? I've been experimenting with various ways to construct the object within the method but nothing seems to be working...