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

Thread: How to import code in NetBeans and make it complete.

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

    Default How to import code in NetBeans and make it complete.

    how to import code in NetBeans...this is game Drawing Envelope without lifting the pen.
    witch mean the player only choose A/B/C/D/E as first move then 2th and so on.
    how do i make it in NetBeans can someone can help me complete this game using the code given.

    /**
     * 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 envelope2
    {
        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'};
                int nodeTotal =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);
                 path[nodeTotal]=currentNode;  // store node passed
                 char prevNode='\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");
                }
     
                // Display current path
                for (int i=0; i < path.length; i++)
                {
                    if (path[i]!='\0') 
                     System.out.println(i+1+" : "+path[i]);
                    else  System.out.println(i+1+" : "+ '-');
                }
                nodeTotal++;
     
     
            //   3.3 User choose next node
                  char nextNode; 
                  boolean invalidNode= true;
                  int attempt=0;
     
                  do {
                     System.out.println(" Please select next node");
                     userInputStr = in.next();
                     nextNode = userInputStr.charAt(0);
     
            //   3.4 Check  valid choice, repeat if invalid node was chosen
     
                     if (nextNode == currentNode){
                        System.out.println("!!! Invalid path- Same Node");
                        invalidNode = true;
                     }
                     else {
     
                            if (nextNode == prevNode){
                               System.out.println("!!! Invalid path- repeated path");
                               invalidNode = true;
                             }
                            else invalidNode = false; // next node selected is legal        
                          }
     
                     for (int i=1; i < path.length; i++) {
                        if ((currentNode == path[i]) && (nextNode == path[i-1])) {
                           System.out.println("!!! Invalid path- repeated path");
                            invalidNode = true; //path already exist
                            break;
                        }  
     
                        else if ((currentNode == path[i]) && (nextNode == path[i+1])) {
                                System.out.println("!!! Invalid path- repeated path");
                                invalidNode = true; //path already exist
                                break;
                              }  
                      } 
                  } while (invalidNode);             
     
                path[nodeTotal] = nextNode;
                prevNode=currentNode; // to keep track repeated path- not allowed
                currentNode = nextNode;
     
     
                if (nodeTotal == 8) {
     
                    // Display complete path
                  for (int i=0; i < path.length; i++)
                  {
                    if (path[i]!='\0') 
                     System.out.println(i+1+" : "+path[i]);
                    else  System.out.println(i+1+" : "+ '-');
                  }
                  System.out.println("CONGRATULATIONS !!!");
                   gameover = true;
                }
            //   3.5 if game not over
            //         3.5.1 Store choice in path
            //         3.5.2 Repeat 3.2
     
     
         } // gameover  
     
       }// main
    } // envelope
    Last edited by helloworld922; June 27th, 2012 at 12:42 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,541
    My Mood
    Hungover
    Thanks
    145
    Thanked 648 Times in 553 Posts

    Default Re: How to import code in NetBeans and make it complete.

    Please use the code tags when posting code.

    Which part of this is giving you trouble? What happens when you compile it?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: How to import code in NetBeans and make it complete.

    When i compile it OK completely work but i dont know how to use this coding in Netbeans.
    first of all this code is from BlueJ but i going to use Netbeans i just dont know how.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,541
    My Mood
    Hungover
    Thanks
    145
    Thanked 648 Times in 553 Posts

    Default Re: How to import code in NetBeans and make it complete.

    What exactly does that mean? What do you mean by "use this coding"? You should be able to type the same code in any editor.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to make this Java Code in NetBeans
    By Chemical91 in forum Java IDEs
    Replies: 4
    Last Post: June 26th, 2012, 05:22 AM
  2. Replies: 0
    Last Post: April 14th, 2012, 12:22 PM
  3. [SOLVED] Import a library to Netbeans
    By Melawe in forum Java IDEs
    Replies: 2
    Last Post: March 16th, 2012, 08:48 AM
  4. Replies: 1
    Last Post: July 7th, 2011, 01:42 PM
  5. How to complete code
    By Shay in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 5th, 2010, 02:59 PM