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 10 of 10

Thread: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

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

    Default [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    So, Let's get to the point. I need some hint for the algorithm for my project.
    One monster will attack earth. It doesn't need army because the monster can duplicate itself.
    The monster divided into 2 kinds, BLACK monster and WHITE monster.
    BLACK MONSTER divided itself into BLACK monster and WHITE monster.
    WHITE MONSTER divided itself into BLACK monster and 2 WHITE monster each day.

    At the invasion day (Day-0) only the BLACK monster come.
    I must make the program that count the amount BLACK monster, WHITE monster, and total both of them at n-day.

    The example of output is like this:
     
    Input days: 2
     
    output example:
    Days -0
    ================================
    BLACK monster 0 <> into BLACK monster 1
    BLACK monster 0 <> into WHITE monster 1
    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
    Days -2
    ================================
    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
    BLACK monster 2 <> into BLACK monster 3
    BLACK monster 2 <> into WHITE monster 4
    WHITE monster 2 <> into BLACK monster 5
    WHITE monster 2 <> into WHITE monster 5
    WHITE monster 2 <> into WHITE monster 6
    WHITE monster 3 <> into BLACK monster 5
    WHITE monster 3 <> into WHITE monster 7
    WHITE monster 3 <> into WHITE monster 8
    Total
    ================================
    BLACK monster: 5
    WHITE monster: 8
    TOTAL: 13

    Anyone can help me to make this program? I hope you can guide me step-by-step to complete this
    I really appreciate that.
    Sorry my english isn't good enough


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,503
    My Mood
    Mellow
    Thanks
    153
    Thanked 610 Times in 597 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    Create a Monster class with (at least) the attributes 'color' and 'number'. The attribute color doesn't actually have to be the type Color. It could be a String, a boolean, a number, or . . . You decide how you want to define black and white.

    Create a collection or appropriate data structure (perhaps 2 or 3) to store Monster objects. A Queue or two might be useful, but I haven't thought it completely through.

    Start with 1 black monster as specified, ask the user how many days the simulation should run, then follow the simulation's rules to create the monster objects for each day, reporting the results at the end of each day. Report the total monster objects created at the end of the simulation.

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

    noobies (April 16th, 2014)

  4. #3
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    Okay I'm confused now, but I try to make the code. Are you mean like this?
    package projek3;
     
    import java.util.Scanner;
     
    /**
     *
     * @author Hengky
     */
    public class Projek3 {
     
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            System.out.print("Input days: ");
            int day= input.nextInt();
        }
        public static void monster (String color, int number){
     
        }
     
    }
    Err.. theen?

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,503
    My Mood
    Mellow
    Thanks
    153
    Thanked 610 Times in 597 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    Sorry for the delay. The site was apparently down when I tried to get on yesterday.

    What are you confused about? If you're unable, unsure, or just hesitant to create a program with more than one class, or you know nothing about data structures like queues, then you need to say so. If you are limited by policy to use only that which the instructor has taught you, then you need to let us know which Java tools you can use. Or if this is a personal project you've taken on just to learn and practice programming basics, let us know that.

    The code you posted to get the user's input is a start, but what about the Monster class? What did you have in mind for the monster() method you've outlined? Comments in your code that describe the code's purpose would be helpful.

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

    noobies (April 18th, 2014)

  7. #5
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    Yes, I don't understand queue yet. This is for my personal project. The reason I created monster() method is I tried to describe your explanation about creating Monster class, and I tried to write it down into subroutine. But, actually I've no idea about subroutine yet, I just tried it to realize your explanation.
    But it seems wrong, hahaha.
    I just understand java from if statement, looping, sorting, searching, arrays. So, can the program completed without queue but just with my understanding here? Can you give me hints?
    Sorry my English isn't good.

  8. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,503
    My Mood
    Mellow
    Thanks
    153
    Thanked 610 Times in 597 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    A queue (or two) would be a convenient way to keep track of the Monster objects first as they are created, reported, and then as they are used to create the next generation of monsters. Since the monsters you've described have multiple characteristics that are important to produce the output you've shown, they would best be managed as objects.

    I'm all for self study and pursuing your own projects, but it's important to study topics in the right order so that you obtain an appropriately broad and deep foundation of the basics. It's also important to be adequately prepared for the projects you take on so that you don't become discouraged and give up. It's not easy to know what you need before imagining and then starting a project. I believe you also asked for a site with projects to practice. All of this put together suggests to me that you need guidance in choosing what to study and what projects to take on. I suggest you restart your studies with a book to give you the guidance and practice you need in the right order and to build your confidence in and experience with the basic skills.

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

    noobies (April 20th, 2014)

  10. #7
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    This project is from my book, the old one actually that my brother has years ago. It is said this is the project for the concepts of java around if statement until array.
    Actually I can simply go on skip this project from the book, but its make me itchy to solve this. -_-
    I keep trying then.

  11. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,503
    My Mood
    Mellow
    Thanks
    153
    Thanked 610 Times in 597 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    By "until array" do you mean using arrays? If so, they're pushing you to a solution using parallel arrays which is a painful step prior to creating a Monster class. I recommend avoiding the parallel arrays approach as an unnecessary pain suffered simply to reinforce that it's a bad design. Just as you can take a stranger's word that stabbing yourself in the eye with a sharp pencil is a bad idea, accept that using parallel arrays to store data is a bad approach.

    Another issue with using arrays for this problem is that you don't know how large the arrays will need to be.

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

    noobies (April 20th, 2014)

  13. #9
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    Yup, I will never using parallel arrays :p
    My understanding is until searching. But, if I really stuck for this project, I'll skip it for now.
    When I figure it out and make some codes, I'll post the thread in "What wrong with my code?"

  14. #10
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Re: [HELP] Trouble To Understanding The Algorithm of my second project (MONSTER DUPLICATE ATTACK :D)

    This the code:
    [HELP] MONSTER DUPLICATE ATTACK

Similar Threads

  1. [SOLVED] [HELP] [HELP] Trouble To Understanding The Algorithm of my project
    By noobies in forum Algorithms & Recursion
    Replies: 4
    Last Post: April 15th, 2014, 09:01 PM
  2. Trouble understanding what this is asking.
    By daniel95 in forum Object Oriented Programming
    Replies: 7
    Last Post: October 29th, 2013, 05:19 PM
  3. Having trouble understanding recursive methods??
    By orbin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 17th, 2012, 12:08 AM
  4. Having trouble understanding Int Logs.
    By orbin in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 10th, 2012, 12:30 PM
  5. Inheritance trouble understanding how to use it?
    By orbin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 21st, 2012, 11:24 AM