Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: [HELP] MONSTER DUPLICATE ATTACK

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default [HELP] MONSTER DUPLICATE ATTACK

    I deleted my code, for safety, hahaha
    Last edited by noobies; May 16th, 2014 at 11:47 PM. Reason: The Problem already SOLVED


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    Not sure why you started a new topic, but I'll leave it for now.

    Code without comments is very difficult to read and understand, doubly difficult when variable names are either nonsensical or in a foreign language.

    Further, your questions don't make sense:

    1. The count of monsters is okay, but the numbers in the monster is wrong. Can you please explain what's right and what's wrong?

    2. Write a program that works or a formula to determine the number of Monster objects after day N that can be calculated with pencil and paper to see how large of an array is required. An alternative is to use an ArrayList or a collection of your own making that grows as needed.

    3. This is not a question but a statement that recognizes the program doesn't do what you'd like it to. This is actually the more interesting point, because it suggests your program design either 1) did not consider the requirements, or 2) isn't done yet.

    To develop the requirements, consider the required output:

    Days -1
    ================================
    BLACK monster 1 <> into BLACK monster 1
    BLACK monster 1 <> into WHITE monster 1
    WHITE monster 1 <> into BLACK monster 2
    WHITE monster 1 <> into WHITE monster 2
    WHITE monster 1 <> into WHITE monster 3

    and then:

    Total
    ================================
    BLACK monster: 5
    WHITE monster: 8
    TOTAL: 13

    This shows that for each day, the program must:

    1. have access to the Monster objects created the previous day and existing before then
    2. know the color of each existing Monster object
    3. know the number of each existing Monster object
    4. number Black and White Monster objects separately (a requirement I question)
    5. follow the game's rules to create new Monster objects for the current day
    6. know the next available number for each color Monster object

    and for all days in a single run:

    7. keep track of the number of White Monster objects created
    8. keep track of the number of Black Monster objects created
    9. keep track of the total number of Monster objects created

    and then for the next day

    10. store all existing Monster objects in a collection for retrieval

    Plus maybe a few others I missed. The value of a Monster class is that it can be used to store each Monster object's characteristics or attributes. The Monster objects can then be stored in a collection and then for each day (roughly):

    1. retrieved,
    2. cloned,
    3. existing and new stored in a collection,
    4. counted, and
    5. reported.

    This problem is very difficult without a Monster class, somewhat less difficult with a Monster class using a Monster[] array, less difficult still using a Monster class stored in an ArrayList<Monster>. Even at the least difficult, it's still a challenging problem for a beginner who didn't know how to write a loop two days ago.

    That you've come this far in such a short amount of time is a good thing. You're doing well, but you're attempting to accomplish tasks that require learning to use new tools out of order and without structure and sufficient basis for understanding. I recommend that you slow down. Get a book and start at the beginning, work each chapter in order completing every sample and every exercise in each chapter. Depending on how much free time you have and how hard you work, you can expect to breeze through a problem like this using the tools I've described in roughly 6 months.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    noobies (April 29th, 2014)

  4. #3
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    I deleted my code, for safety, hahaha
    Last edited by noobies; May 16th, 2014 at 11:47 PM.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    Okay. Keep us posted, and good luck.

  6. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    How are your studies going? Have you been working this problem? I've coded my own solution, because it is an interesting simulation and use of queues. If you'd like to discuss my approach, let me know.

    Here's an example of a 5-day output. (I didn't agree with (or like) some of the interpretations of the rules, so I modified them a bit):
    ========= Day 0 =========
    BLACK monster number 1
     
    Total monsters by color: 
    White = 0
    Black = 1
     
    ========= Day 1 =========
    BLACK monster number 1
    BLACK monster number 1 --> BLACK monster number 2
    BLACK monster number 1 --> WHITE monster number 1
     
    Total monsters by color: 
    White = 1
    Black = 2
     
    ========= Day 2 =========
    BLACK monster number 1
    BLACK monster number 1 --> BLACK monster number 3
    BLACK monster number 1 --> WHITE monster number 2
    BLACK monster number 2
    BLACK monster number 2 --> BLACK monster number 4
    BLACK monster number 2 --> WHITE monster number 3
    WHITE monster number 1
    WHITE monster number 1 --> BLACK monster number 5
    WHITE monster number 1 --> WHITE monster number 4
    WHITE monster number 1 --> WHITE monster number 5
     
    Total monsters by color: 
    White = 5
    Black = 5
     
    ========= Day 3 =========
    BLACK monster number 1
    BLACK monster number 1 --> BLACK monster number 6
    BLACK monster number 1 --> WHITE monster number 6
    BLACK monster number 3
    BLACK monster number 3 --> BLACK monster number 7
    BLACK monster number 3 --> WHITE monster number 7
    WHITE monster number 2
    WHITE monster number 2 --> BLACK monster number 8
    WHITE monster number 2 --> WHITE monster number 8
    WHITE monster number 2 --> WHITE monster number 9
    BLACK monster number 2
    BLACK monster number 2 --> BLACK monster number 9
    BLACK monster number 2 --> WHITE monster number 10
    BLACK monster number 4
    BLACK monster number 4 --> BLACK monster number 10
    BLACK monster number 4 --> WHITE monster number 11
    WHITE monster number 3
    WHITE monster number 3 --> BLACK monster number 11
    WHITE monster number 3 --> WHITE monster number 12
    WHITE monster number 3 --> WHITE monster number 13
    WHITE monster number 1
    WHITE monster number 1 --> BLACK monster number 12
    WHITE monster number 1 --> WHITE monster number 14
    WHITE monster number 1 --> WHITE monster number 15
    BLACK monster number 5
    BLACK monster number 5 --> BLACK monster number 13
    BLACK monster number 5 --> WHITE monster number 16
    WHITE monster number 4
    WHITE monster number 4 --> BLACK monster number 14
    WHITE monster number 4 --> WHITE monster number 17
    WHITE monster number 4 --> WHITE monster number 18
    WHITE monster number 5
    WHITE monster number 5 --> BLACK monster number 15
    WHITE monster number 5 --> WHITE monster number 19
    WHITE monster number 5 --> WHITE monster number 20
     
    Total monsters by color: 
    White = 20
    Black = 15
     
    ========= Day 4 =========
    BLACK monster number 1
    BLACK monster number 1 --> BLACK monster number 16
    BLACK monster number 1 --> WHITE monster number 21
    BLACK monster number 6
    BLACK monster number 6 --> BLACK monster number 17
    BLACK monster number 6 --> WHITE monster number 22
    WHITE monster number 6
    WHITE monster number 6 --> BLACK monster number 18
    WHITE monster number 6 --> WHITE monster number 23
    WHITE monster number 6 --> WHITE monster number 24
    BLACK monster number 3
    BLACK monster number 3 --> BLACK monster number 19
    BLACK monster number 3 --> WHITE monster number 25
    BLACK monster number 7
    BLACK monster number 7 --> BLACK monster number 20
    BLACK monster number 7 --> WHITE monster number 26
    WHITE monster number 7
    WHITE monster number 7 --> BLACK monster number 21
    WHITE monster number 7 --> WHITE monster number 27
    WHITE monster number 7 --> WHITE monster number 28
    WHITE monster number 2
    WHITE monster number 2 --> BLACK monster number 22
    WHITE monster number 2 --> WHITE monster number 29
    WHITE monster number 2 --> WHITE monster number 30
    BLACK monster number 8
    BLACK monster number 8 --> BLACK monster number 23
    BLACK monster number 8 --> WHITE monster number 31
    WHITE monster number 8
    WHITE monster number 8 --> BLACK monster number 24
    WHITE monster number 8 --> WHITE monster number 32
    WHITE monster number 8 --> WHITE monster number 33
    WHITE monster number 9
    WHITE monster number 9 --> BLACK monster number 25
    WHITE monster number 9 --> WHITE monster number 34
    WHITE monster number 9 --> WHITE monster number 35
    BLACK monster number 2
    BLACK monster number 2 --> BLACK monster number 26
    BLACK monster number 2 --> WHITE monster number 36
    BLACK monster number 9
    BLACK monster number 9 --> BLACK monster number 27
    BLACK monster number 9 --> WHITE monster number 37
    WHITE monster number 10
    WHITE monster number 10 --> BLACK monster number 28
    WHITE monster number 10 --> WHITE monster number 38
    WHITE monster number 10 --> WHITE monster number 39
    BLACK monster number 4
    BLACK monster number 4 --> BLACK monster number 29
    BLACK monster number 4 --> WHITE monster number 40
    BLACK monster number 10
    BLACK monster number 10 --> BLACK monster number 30
    BLACK monster number 10 --> WHITE monster number 41
    WHITE monster number 11
    WHITE monster number 11 --> BLACK monster number 31
    WHITE monster number 11 --> WHITE monster number 42
    WHITE monster number 11 --> WHITE monster number 43
    WHITE monster number 3
    WHITE monster number 3 --> BLACK monster number 32
    WHITE monster number 3 --> WHITE monster number 44
    WHITE monster number 3 --> WHITE monster number 45
    BLACK monster number 11
    BLACK monster number 11 --> BLACK monster number 33
    BLACK monster number 11 --> WHITE monster number 46
    WHITE monster number 12
    WHITE monster number 12 --> BLACK monster number 34
    WHITE monster number 12 --> WHITE monster number 47
    WHITE monster number 12 --> WHITE monster number 48
    WHITE monster number 13
    WHITE monster number 13 --> BLACK monster number 35
    WHITE monster number 13 --> WHITE monster number 49
    WHITE monster number 13 --> WHITE monster number 50
    WHITE monster number 1
    WHITE monster number 1 --> BLACK monster number 36
    WHITE monster number 1 --> WHITE monster number 51
    WHITE monster number 1 --> WHITE monster number 52
    BLACK monster number 12
    BLACK monster number 12 --> BLACK monster number 37
    BLACK monster number 12 --> WHITE monster number 53
    WHITE monster number 14
    WHITE monster number 14 --> BLACK monster number 38
    WHITE monster number 14 --> WHITE monster number 54
    WHITE monster number 14 --> WHITE monster number 55
    WHITE monster number 15
    WHITE monster number 15 --> BLACK monster number 39
    WHITE monster number 15 --> WHITE monster number 56
    WHITE monster number 15 --> WHITE monster number 57
    BLACK monster number 5
    BLACK monster number 5 --> BLACK monster number 40
    BLACK monster number 5 --> WHITE monster number 58
    BLACK monster number 13
    BLACK monster number 13 --> BLACK monster number 41
    BLACK monster number 13 --> WHITE monster number 59
    WHITE monster number 16
    WHITE monster number 16 --> BLACK monster number 42
    WHITE monster number 16 --> WHITE monster number 60
    WHITE monster number 16 --> WHITE monster number 61
    WHITE monster number 4
    WHITE monster number 4 --> BLACK monster number 43
    WHITE monster number 4 --> WHITE monster number 62
    WHITE monster number 4 --> WHITE monster number 63
    BLACK monster number 14
    BLACK monster number 14 --> BLACK monster number 44
    BLACK monster number 14 --> WHITE monster number 64
    WHITE monster number 17
    WHITE monster number 17 --> BLACK monster number 45
    WHITE monster number 17 --> WHITE monster number 65
    WHITE monster number 17 --> WHITE monster number 66
    WHITE monster number 18
    WHITE monster number 18 --> BLACK monster number 46
    WHITE monster number 18 --> WHITE monster number 67
    WHITE monster number 18 --> WHITE monster number 68
    WHITE monster number 5
    WHITE monster number 5 --> BLACK monster number 47
    WHITE monster number 5 --> WHITE monster number 69
    WHITE monster number 5 --> WHITE monster number 70
    BLACK monster number 15
    BLACK monster number 15 --> BLACK monster number 48
    BLACK monster number 15 --> WHITE monster number 71
    WHITE monster number 19
    WHITE monster number 19 --> BLACK monster number 49
    WHITE monster number 19 --> WHITE monster number 72
    WHITE monster number 19 --> WHITE monster number 73
    WHITE monster number 20
    WHITE monster number 20 --> BLACK monster number 50
    WHITE monster number 20 --> WHITE monster number 74
    WHITE monster number 20 --> WHITE monster number 75
     
    Total monsters by color: 
    White = 75
    Black = 50

  7. #6
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    deleted
    Last edited by noobies; May 16th, 2014 at 11:47 PM.

  8. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    Stack is last in, first out (LIFO). New items are pushed onto the top of the stack and items removed from the stack are popped off the top.

    Queue is first in, first out (FIFO). New items are added to the back of the collection or onto the end, and items removed from the queue are taken from the head of the line and all items left in the line move forward, towards the head of the line.

    The reason a queue works well for this problem is that each monster is added to the queue as it is created, each monster is removed from the queue in the order it was created and added to another queue, just ahead of all monsters that are spawned from it. The order of the monsters is always preserved.

    Predicting the size of the array required would require a formula that calculates the number of monsters on for a given number of simulated invasion days. My simulation doesn't agree with the numbers you're getting, but I'll use mine as an example:

    Day 0: 1
    Day 1: 3
    Day 2: 10
    Day 3: 35
    Day 4: 125
    Day 5: 450
    Day 6: 1,625
    Day 7: 5,875
    Day 8: 21,250
    Day 9: 76,875
    Day 10: 278,125

    I think there's a progression there that can be generalized with an equation, but I'll leave that to you for your own numbers. An estimate of the number of monsters existing that is just bigger than the actual number of monsters at the end of a certain number of days would be good enough.

    If you don't know ArrayList, now would be a good time to learn it. An ArrayList will grow in size as needed. If you are unable to learn/use ArrayList, then you can create your own 'adjustable' array that increases in size as needed. It's not that hard and would be a good exercise.

  9. The Following User Says Thank You to GregBrannon For This Useful Post:

    noobies (May 8th, 2014)

  10. #8
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    I like the concept of 'adjustable' array, you said. I'll try to figure it out. And I'll study about ArrayList after it.
    Yes, now I understand Stack, because I use it for my college project.
    I'll mark this post to SOLVED then, thank you for your help, and wish me luck for my next project, hahahaha.

  11. #9
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default Re: [HELP] MONSTER DUPLICATE ATTACK

    Hey Greg! Now I understand the stack/queue and ArrayList too
    And if you don't mind please guide me again at this thread. Thanks!
    http://www.javaprogrammingforums.com...tml#post148102

Similar Threads

  1. Replies: 9
    Last Post: April 28th, 2014, 11:08 AM
  2. Find the password with dictionary attack
    By mortis1572 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 19th, 2010, 10:07 PM