Help with horoscope


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Help with horoscope

  1. #1
    Join Date
    May 2005
    Posts
    4

    Help with horoscope

    I am in dire need of help. I'm helping a friend but I seem to be stuck (been a while since I did this, still wanna make a good impression ). She's doing a chineese horoscope and the setup i simple:

    Get the user to input a birthday i.e. yyyy-mm-dd, then with the help of some textfiles give the user a "horoscope". The textfiles looks like this:

    year.txt
    1901-01-01
    1902-01-24
    1903-02-10
    ...
    ...
    animal.txt
    rat
    monkey
    boar
    ...
    monkey.txt
    Metal Monkey - 1860, 1920, 1980

    Random text about bein a metal monkey
    ...

    Water Monkey - 1872, 1932, 1992

    Random text about bein a Water monkey.
    ...
    My questions:
    1) How do I write a good input?
    2) How do I compare the input with the dates stated in the years.txt?
    3) How do I given the birth year find and print the correct part of the monkey.txt-file?

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Assumptions:

    Each line in year.txt tells when the year of the animal on the corresponding line
    in animal.tx begins, so (one of) the the years of the monkey started
    jan.24 1902 and lasted till feb.9 1903, am I right ?

    Well, if so you could do this:

    a: get user's date input (Ill come to that), store in a Calendar object.

    Code:
    Calendar birthDate=Calendar.getInstance();
    birthDate.set(yearIn, monthIn, dateIn);
    b: read each date-line in year.txt, while counting lines, use BufferedReader
    for this.
    Pseudo code:
    Code:
    Calendar fileDate=Clendar.getInstance();
    int cnt=0;
    while (more lines) {
      extract year, month and date from line read
      fileDate.set(yearRead, monthRead, dateRead);
      if (fileDate.after(birthDate)) break;
      cnt++;
    }
    if (cnt==0) {
      give message like "too far back in time, no data"
      return;
    }
    Now read the same number of lines from animal.txt (zero based of course).
    take the animal name found at this line, concatenate that name with
    ".txt" and use that name for opening the corresponding .txt file.

    Now this is where it gets a bit tricky; the monkey.txt file has several
    delimiter lines, each being the start of text for a specific monkey type,
    and the lines also contains a comma delimited list of years. Extracting these
    years from the line is a piece of cake, but the problem to be solved is how
    to detect these lines ?
    Will you have to check for the patten: some text followed by a dash and then a monotone sequence of integers and commas, or is there a cleaner
    way (blank line between each monkey type ?)
    Last edited by sjalle; 05-06-2005 at 08:13 AM.
    eschew obfuscation

  3. #3
    Join Date
    May 2005
    Posts
    4
    Quote Originally Posted by sjalle
    Will you have to check for the patten: some text followed by a dash and then a monotone sequence of integers and commas, or is there a cleaner
    way (blank line between each monkey type ?)
    The monkey.txt (and other animals) looks as:
    Metal Rabbit - 1891, 1951, 2011

    This type of Rabbit could be sturdier physically and mentally than
    Rabbits belonging to other elements. He will not be as compromising
    either. He has unshakable faith in his own powers of observation and
    deduction and more often than not he is convinced he has the right
    answer and solutions to this problems. He can assume responsibility
    admirably well and will displays a good deal of initiative in his
    work.

    Metal matched with his animal sign will make him more preoccupied with
    his desires, goals and creative urges. He will be more cunning, but
    his ambitiousness will be carefully concealed with cool logic and
    intelligence.

    A connoisseur par excellence, he will know how to live and will savor
    the good things life has to offer in a refined way. While he may be
    indifferent to the opinions of others, he is emotionally and
    physically moved by good art, music and other forms of beauty. His
    basic self-assurance and discerning eye will make him an excellent
    judge of any kind of creative art forms; he may become a collector of
    great distinction, if he has the means, because of his impeccable
    taste. Whatever career he chooses he will make his mark early as he is
    naturally a thorough and devoted worker.

    But like all true romantic spirits, this type of Rabbit could be
    inclined to dark moods, and works well only when he is sufficiently
    inspired. Ardent in love and with great depth and foresight, still he
    will allow only a handful of people into the inner sanctum of his life
    because of his many hidden inhibitions.


    Water Rabbit - 1903, 1963, 2023

    This is a meditative type of Rabbit with a fragile and emotional
    nature. He cannot bear harassment or any other unpleasantness, such as
    dissent and bickering. Perhaps this is due to the fact that he is too
    empathic and can pick up the thoughts and feelings of others with
    uncanny accuracy.

    He will possess an excellent memory and may have the kind of mental
    power that, without his knowing it, transmits his ideas to
    others. Consequently, he attracts the people he wants, and he may be
    surprised by the many supporters who really to his defense when he
    least expects it.

    However, he is a subjective soul and his perspective gets distorted by
    the emotional barriers he sets up. He is not very decisive and in many
    cases could easily fall in with the dictates of others.

    His delicate sensitivity makes him dwell too much on the past and
    hence he is often reminiscing on long past injuries and indulging in
    self-pity. In his negative moods, he suspects other's motives, is
    uncommunicative and over imaginative. In his positive state, he could
    call upon all the cosmic powers to come to his aid. He is never
    without friends and influence if he does not carry his neutrality to
    extremes.


    Wood Rabbit - 1915, 1975, 2035

    When Wood is exalted in this lunar sign already governed by Wood, it
    could produce a generous and especially understanding Rabbit who will
    be too charitable at times for his own good. No doubt he has real and
    solid ambitions, but often he is intimidated by authority and may
    choose to ignore mistakes made in his presence in order to maintain
    the status quo. As a result, others are tempted to take advantage of
    his sympathetic and permissive attitude.

    However, this type of Rabbit usually works out well. He thrives in
    large corporations or other institutions where he can slowly and
    diplomatically climb the ladder of success, one rung at a time. Group
    effort and togetherness appeal to him and give him the kind of
    security and reassurance he needs. But because of his innate desire to
    feel part of the group, he may become a but too bureaucratic and hedge
    when he has to make a decision that might offend people or set a
    precedent for a controversial case. In his refusal to meddle or take
    sides, he may end up hurting everyone, including himself. He should be
    more discriminating and decisive and take the necessary steps to
    insulate himself against those who prey on his generous nature. As he
    is one who is able to bend gracefully without ever breaking, this
    Rabbit will have no trouble fitting in anywhere he chooses.


    Fire Rabbit - 1927, 1987, 2047

    Definitely a demonstrative, fun loving and affectionate type of
    Rabbit. He has more strength of character than the other Rabbits. In
    spite of Fire making him more temperamental, he is still able to mask
    his emotions with charm and diplomacy.

    His personality is easy and natural. People respond positively to his
    ideas because he expresses them so well.

    Fire may take him prone to emotion and outspoken in expressing his
    wants. His more capable of leadership than other Rabbits and his rule
    is tempered with discretion and moderation. Despite his outgoing and
    progressive ways, he will never approve of outright confrontation with
    his enemies and will prefer to use subtle plots or deal with
    go-betweens as natives of his sign are so adept at doing.

    This type of Rabbit will have a high level of intuition and even
    psychic ability. He is intensely aware of changes in his surroundings
    and easily moved to anger, hurt or disappointment. He could also
    become terribly neurotic when negative. He requires approval,
    whole-hearted support and inspiration in order to sparkle.


    Earth Rabbit - 1879, 1939, 1999

    A serious and steadfast type of Rabbit, he has definite patterns of
    thought an dis capable of well-calculated moves. he deliberates before
    giving in to his emotional inclinations. His balanced and rational
    personality wins him favor in the eyes of his superiors, as does his
    realistic approach to his goals.

    The Earth element makes him more constant and less indulgent, although
    his constancy will be of a passive sort. His introverted nature
    causes him to turn inward when beset with problems and he must be in
    accord with his inner self before he acts. He never hesitates to
    appropriate whatever resources are available and will use them wisely.

    He is materialistic sort of person, and his well-being is his prime
    concern, making him indifferent to the needs of others when they are
    not in accordance with his plans. Still, he possesses the humility to
    acknowledge his shortcomings and will strive to overcome them if he
    can.
    Notice the extra line of blank space before each new title, maybe I can use that?

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    OK, just a sec and I will post the code, must test it first
    eschew obfuscation

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Here is a console version.

    Its a console version, no GUI.
    I've just tested it a little bit as I haven't got the complete chinese
    library...

    Note: you may want to remove the package directive on top and a couple
    of System.out.println I've left in there for debugging.
    Attached Files Attached Files
    Last edited by sjalle; 05-06-2005 at 10:55 AM.
    eschew obfuscation

  6. #6
    Join Date
    May 2005
    Posts
    4
    Quote Originally Posted by sjalle
    Its a console version, no GUI.
    I've just tested it a little bit as I haven't got the complete chinese
    library...

    Note: you may want to remove the package directive on top and a couple
    of System.out.println I've left in there for debugging.
    Thanks a bunch!!

    Edit: stupid question removed!

    Thanks for all the help!
    Last edited by InterWill; 05-06-2005 at 12:36 PM.

  7. #7
    Join Date
    May 2005
    Posts
    4
    Sorry for digging up an old thread.

    If I want to use StringTokenizer instead of .split how do I do? Is the syntax the same?

  8. #8
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    The syntax is not the same, StringTokenizer is out, it deals with Enumeration,
    iterators and is a general pain compared with split, may it rest in peace.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center