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.
Code java:
/**
* 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
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?
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.
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.