View Single Post
Old 01-26-2013, 05:08 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The get* methods don't accept any parameters. They simply return the result of the datatype specified. So the getDate would return a type OurDate which will be what is stored within the property date (which I don't like the property name of, but that's not my call). Setters are reverse, so the set* methods accept the datatype provided within the brackets and return void. Those would set the associated property.

Since you are just using an array, you simply iterate it and check each item until you reach the end. To check them, you simply iterate the activities and compare each existing activity. You can simply check each field, or if you are far enough to do it, implement the Comparator interface and write the compareTo. A hint to do that with just comparisons of each property:
PHP Code:
boolean bConflict false;
for (
int i 0this.activities.length && !bConflict; ++i)
{
    
Event e this.activities[i];
    if (
e.getDate().isEqual(myNewEvent.getDate()))
    {
        if (
e.getTime().isEqual(myNewEvent.getTime()))
        {
            
// this condition is no good.
            
bConflict true;
        }
    }
}

if (!
bConflict)
{
    
// this is a.o.k.
}
else
{
    
// this is no good.

I'm not sure why you've written the isEqual method. Java does have a built in equals method that can be overridden, the only difference is you have to check the argument instanceof type to verify that its the proper datatype for the equals check. If anything, I'd suggest using the equals, or if isEqual is a must I'd override the equals and than chain the isEqual to it.

Also, the array will potentially give you problems. Since you cannot resize the array by simply appending to it, you'll need to keep track of the size or use try/catch exceptions to see if it goes out of bounds (currently you do have a variable for the size of the array, which I assume is the existing items currently, and can be compared to the length). Copying an array is a simple matter of constructing a new array that is larger, than iterating each item to add to it, then assigning that back to the member. Or you can use the Arrays class which has a copyOf method that should do the trick if you need to resize. If you weren't stuck on Event[] datatype in the instructions, I'd actually suggest a priority queue based on the Date and Time provided. Add an event, and it automatically inserts it based on date and time, so when you iterate the list it would be sequential in order of date and time.

You'll need to look over the date handling as well. Its not quite as cut and dry as you have here; if you change the month, the number of days will change which may alter the currently assigned day. Same goes with the year if it were february 29 for example.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
blahblahblah (01-29-2013)