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

Thread: How to make this Java Code in NetBeans

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to make this Java Code in NetBeans

    Ok this is game name Envelope but i dont know how does it work.??please i need a hand.
    /**
     * Draw envelope without lifting your pen.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
     
    import java.util.Scanner; // to read input
    public class envelope
    {
        public static void main (String [] args) {
     
     
            //1. Display Instruction
     
            System.out.println("In this game player must choose path to draw an envelope");
            System.out.println("Whithout lifting a pen");
            System.out.println("    E");
            System.out.println("   /\\");
            System.out.println("  /  \\");
            System.out.println("  ___");
            System.out.println("D     C");
            System.out.println(" | X |");
            System.out.println("  ___");
            System.out.println("A     B");
     
            //2. Reset the game environment
            //   Possible choice for node A = {B,C,D}
                char [] nodeA = {'B','C','D'};
                char [] nodeB={'A','C','D'};
                char [] nodeC={'A','B','D','E'};
                char [] nodeD={'A','B','C','D'};
                char [] nodeE={'C','D'};
     
            // path chosen by user
                char [] path = {'\0','\0','\0','\0','\0','\0','\0','\0','\0'};
     
            // object Scanner to read input from keyboard
                 Scanner in = new  Scanner (System.in);
     
            //3. Start the game
            //   3.1 User choose node
                 System.out.println(" Please select node to start: A, B, C, D or E");
                 String userInputStr = in.next();
                 char currentNode = userInputStr.charAt(0);
     
            //   3.2 Display possible node
                 Boolean gameover = false;
                 while (!gameover) {
                 switch (currentNode) {
                     case 'A' : 
                         System.out.println("Choices");
                         for (int i=0; i < nodeA.length; i++)
                             System.out.print(nodeA[i]+" ");
                         System.out.println();
                         break;
                      case 'B' : 
                         System.out.println("Choices");
                         for (int i=0; i < nodeB.length; i++)
                             System.out.print(nodeB[i]+" ");
                         System.out.println();
                         break;
                      case 'C' : 
                         System.out.println("Choices");
                         for (int i=0; i < nodeC.length; i++)
                             System.out.print(nodeC[i]+" ");
                         System.out.println();
                         break;
                     case 'D' : 
                         System.out.println("Choices");
                         for (int i=0; i < nodeD.length; i++)
                             System.out.print(nodeD[i]+" ");
                         System.out.println();
                         break;
                     case 'E' : 
                         System.out.println("Choices");
                         for (int i=0; i < nodeE.length; i++)
                             System.out.print(nodeE[i]+" ");
                         System.out.println();
                         break;
                    default: System.out.println("Node NOT in the list");
                }
            //   3.3 User choose next node
                  char nextNode;
                 do {
                    System.out.println(" Please select next node");
                     userInputStr = in.next();
                     nextNode = userInputStr.charAt(0);
     
            //   3.4 Check  valid choice
                    if (nextNode == currentNode){
                      System.out.println("Invalid path- repeat path");
                    }
                } while (nextNode == currentNode);
     
            //   3.5 if game not over
            //         3.5.1 Store choice in path
            //         3.5.2 Repeat 3.2
     
              currentNode = nextNode;
         } // gameover  
     
       }// main
    } // envelope
    Last edited by helloworld922; June 24th, 2012 at 04:44 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to make this Java Code in NetBeans

    Please wrap your code in the
    [highlight=java][/highlight] tags to get the formatting

    Define don't know how it works. I presume this is not your code...then study the lines in the code, step through it with a debugger, or add some println's to evaluate how variables change.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: How to make this Java Code in NetBeans

    The user presumably means that the code works, but they don't know the logic or it or why it is what it is.

    The game goes on forever. You don't seem to have a thing that will end it.

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make this Java Code in NetBeans

    my teacher give it to me.. to finish the work...
    but i really stupid in java..
    my teacher just teach me Raptor and BlueJ Software
    But she didnt teach me how to use NetBeans
    then she want me make a game using the NetBeans.

    She told me to make Envelope game how make Envelope from line to line til it finish completely Envelope.
    then she give me that CODE haaa i raealy confuse..

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make this Java Code in NetBeans

    thanks those who make the code seen good.
    Emm
    but any want can teach me how to edit it make it little dif.. but same woking.
    btw.. how do the will over..i already play it in bluej its good but i dont know how to edit it to see it little dif

Similar Threads

  1. I need help with my Netbeans calculator code
    By geto81 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 5th, 2012, 12:53 PM
  2. I NEED HELP, HOW TO MAKE THIS CODE!!!
    By tahsim in forum Member Introductions
    Replies: 1
    Last Post: March 20th, 2012, 09:05 AM
  3. Java Source Code to UML Diagrams in NetBeans
    By sarkuzi in forum Threads
    Replies: 3
    Last Post: February 7th, 2012, 11:34 AM
  4. How to make HyperLink in java code?
    By abhiM in forum Java Theory & Questions
    Replies: 1
    Last Post: August 24th, 2011, 07:16 AM
  5. How to make Netbeans know about java.nio.file copyTo?
    By jedast in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2011, 08:38 PM

Tags for this Thread