Ask Experts Questions for FREE Help !
Ask
    ndzima2005's Avatar
    ndzima2005 Posts: 2, Reputation: 1
    New Member
     
    #1

    Jun 13, 2009, 05:17 AM
    Write an application using good object orientated principles to simulate a sugarbird
    Write an application using good object orientated principles to simulate a sugarbird feeding on nectar of flowers during daytime.

    1. The observer pattern must be used to open and close the flowers and tell the sugarbird it is time to feed.

    2. The sugarbird and the flowers will be observers of the sun's on and off state.

    3. The sun will stay on for 12 counts and off for 12 counts, i.e.. The flowers will be OPEN for 12 counts and the sugarbird can feed for 12 counts, the other 12 counts the sugarbird will sleep and the flowers will be closed. The sun should keep a global counter, so that we can measure the counts.

    4. There should be 3 events : onDayStart, onDayEnd, onHourChange (change the flower that the bird feeds on). The sugarbird will feed on a different flower every hour, so the sugarbird can feed on 12 flowers in a day. The flowers do not need to do anything on the onHourChange event, the implemenation can be left blank.

    5. There are 10 flowers and they can only be fed on 10 times by the sugarbird.
    Once a flower cannot be fed on, the sugarbird will immediately try another flower.
    NOTE: each flower = 10 visits but each visit must be at a different time

    6. The sugarbird will always randomly pick which flower to feed on.

    7. The flowers will remember their state from day to day. So it will keep their feeding counts until the next day, so the flower will be empty after a few days of feeding.

    8. The application will exit when there is no more nectar in any flower.

    9. No timer needs to be used, the application can simply run and complete as fast as possible.

    10. Print the results, as the application runs to file or console in the following fashion (count in parenthesis :
    ------------------------------------------------
    DAY START (0)

    HOUR CHANGE (0)
    FLOWER-4 (9)

    HOUR CHANGE (1)
    FLOWER-8 (9)

    HOUR CHANGE (2)
    FLOWER-3 (9)

    HOUR CHANGE (3)
    FLOWER-4 (8) <-- note, it randomly changed to the flower already visited.

    ...
    ...
    ...

    DAY END (11)

    HOUR CHANGE (11)
    SLEEP
    HOUR CHANGE (12)
    SLEEP
    HOUR CHANGE (13)

    ...
    ...
    ...

    DAY START (0)

    HOUR CHANGE (0)
    FLOWER-3 (0) <-- flower is empty, immediately choose a new flower
    FLOWER-4 (3)

    HOUR CHANGE (1)
    FLOWER-5 (6)

    HOUR CHANGE (2)
    FLOWER-2 (1)


    ...
    ...
    ...

    DAY END (23)

    ...
    ...
    ...

    EXIT (1233) <-- the total count that the application ran for.
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    Jun 13, 2009, 05:38 AM

    Sounds like a fun project.

    So, short of writing the program for you, what's your question?

    1. You'll need variables indiating times to open and close the flowers.

    2. You'll need to "read" the sun's current state. I'm not sure if this means just the sunrise and sunset time, or whether you'll also have to include the angle of the sun in the sky (probably not).

    3. This is simply an instruction. You'll use a counter to time the sun. 12 counts implies 12 hours. The variable has to be "global" (not local to a subroutine) so that it won't "go away" or lose its value spontaneously.

    4. Events are "triggered" or called when certain things occur. You'll trigger events from sun-watcher subroutines, from an hourly "tick" counters.

    5. I suppose this means that you have to keep track of each flower and how many times it's been fed.

    6. This is pretty obvious. You'll have to use a random number generator.

    7. This is also obvious. Just "persist" the information (Write data to disk. If the program runs continually, you may not have to do that).

    8. So, you have to keep track of the quantity of nectar.

    9. OK.

    10. Straight-forward.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Advise needed to write good CV [ 1 Answers ]

What should I write in "Objective" part of a CV for the post of Account Assistant

How to write a good introduction letter I [ 0 Answers ]

I am an acrobats aand my writing skills in terms of letters is not good , how can write a good selling introduction letter


View more questions Search