Results 1 to 9 of 9
  1. #1
    m4mm4l is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default How do I fix this issue?

    Im getting tons of logical errors...the pdf attached is the assignment sheet of what I have to do. The program I have to do is #1. Please help me mtproj.pdf

    // Guess the Secret Letter Game
    // Designed By: Ben Smith
    // November 10th 2011
    // Version: 1.0

    import hsa. * ;

    public class BenSmithGuessTheSecretLetterGame{
    public static void main(String[] args){
    Console con = new Console(40,60);

    // Variables
    String strMenuSelect;
    String strGuess;
    String strRand;
    String strLetter;
    int intCounter;
    int intCounter2;
    int intPoints;
    int intRand;
    int intLength;
    int intLose;
    int intMaxAlpha;

    // Menu and User menu selection
    con.println("Welcome to Guess the Secret Letter Game!!");
    con.println(" *************");
    con.println(" *****************");
    con.println(" ****** ******");
    con.println(" ***** ******");
    con.println(" **** *****");
    con.println(" *****");
    con.println(" *******");
    con.println(" *******");
    con.println(" ********");
    con.println(" *****");
    con.println(" *****");
    con.println(" *****");
    con.println(" *****");
    con.println(" *****");
    con.println("");
    con.println(" ***");
    con.println(" *****");
    con.println(" ***");

    // Defaulting Variables
    intCounter = 0;
    intCounter2= 0;
    intPoints = 50;
    intRand = 0;
    intLose = 0;
    intMaxAlpha = 26;
    strMenuSelect = "";
    strGuess = "";
    strRand = "";
    strLetter = "";

    // Menu Seleciton
    con.println("Menu");
    con.println("==============");
    con.println("(P)lay Game");
    con.println("(I)nstructions");
    con.println("(Q)uit");
    con.println("Enter you selection here");
    strMenuSelect = con.readLine();

    // Generating the number and assigning a lettetr to a number
    intRand = (int)(Math.random()*26+1);
    if(intRand == 1){
    strRand = ("a");
    }else if(intRand == 2){
    strRand = ("b");
    }else if(intRand == 3){
    strRand = ("c");
    }else if(intRand == 4){
    strRand = ("d");
    }else if(intRand == 5){
    strRand = ("e");
    }else if(intRand == 6){
    strRand = ("f");
    }else if(intRand == 7){
    strRand = ("g");
    }else if(intRand == 8){
    strRand = ("h");
    }else if(intRand == 9){
    strRand = ("i");
    }else if(intRand == 10){
    strRand = ("j");
    }else if(intRand == 11){
    strRand = ("k");
    }else if(intRand == 12){
    strRand = ("l");
    }else if(intRand == 13){
    strRand = ("m");
    }else if(intRand == 14){
    strRand = ("n");
    }else if(intRand == 15){
    strRand = ("o");
    }else if(intRand == 16){
    strRand = ("p");
    }else if(intRand == 17){
    strRand = ("q");
    }else if(intRand == 18){
    strRand = ("r");
    }else if(intRand == 19){
    strRand = ("s");
    }else if(intRand == 20){
    strRand = ("t");
    }else if(intRand == 21){
    strRand = ("u");
    }else if(intRand == 22){
    strRand = ("v");
    }else if(intRand == 23){
    strRand = ("w");
    }else if(intRand == 24){
    strRand = ("x");
    }else if(intRand == 25){
    strRand = ("y");
    }else if(intRand == 26){
    strRand = ("z");
    }
    con.println(strRand); // Prints the randomly gen'd letter on the main console

    // Play Game Code
    if(strMenuSelect.equalsIgnoreCase("P")){
    Console con2 = new Console();
    con2.println("You selected Play Game");
    con2.println("==============");
    con2.println("You currently have 50 points");
    for(intCounter = 0; intCounter <= intLose; intCounter--){
    con2.println("Enter a word with the secret letter in it");
    strGuess = con2.readLine();

    for(intCounter2 = 0; intCounter2 < strGuess.length(); intCounter2++){
    if(strRand.equals (strGuess)){
    strLetter = strGuess.substring(intCounter2, intCounter2+1);
    while(strGuess.equalsIgnoreCase(strRand)){ // Verifys that the guess equals the gen'd letter
    if(strLetter.equalsIgnoreCase(strRand)){ // If the guess equals the gen'd letter then it runs the game code
    intPoints = 0;
    con2.println("YOU WIN!!!");
    break;
    }
    }
    }else if(!strLetter.equalsIgnoreCase(strRand)){
    con2.println("WRONG DEDUCTING 5 POINTS!");
    intPoints = intPoints-5;
    }
    if(strGuess.equalsIgnoreCase(strRand)){
    intLength = strLetter.length();
    }

    if(intPoints < 0){
    con2.println("YOU LOSE!!");
    }
    }
    }
    }

    // Instructions
    if(strMenuSelect.equalsIgnoreCase("I")){
    Console con3 = new Console();
    con3.println("You selected Instructions");
    con3.println("How to play");
    con3.println("====================");
    con3.println("You start with 50 points. A secret");
    con3.println("letter will be generated and you have");
    con3.println("to enter a word with that letter in it.");
    con3.println("If the word you enter does not have");
    con3.println("the secret letter then you will lose 10 ");
    con3.println("points. If the word you enter has the ");
    con3.println("letter once or up to 4 times then you ");
    con3.println("lose 5 points. If the word you enter ");
    con3.println("has the letter 5 times or more you win! ");
    con3.println("If your points are 0 or less then you lose.");
    }

    // Quit
    if(strMenuSelect.equalsIgnoreCase("Q")){
    con.println("=============");
    con.println("Thank you for playing Guess the Secret Letter!!");
    con.println("Created By: Ben Smith");
    }

    }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default Re: How do I fix this issue?

    How do you fix what? Unless you tell us what your problems are we have no idea how to help.

  3. #3
    kevinn205 is offline Member
    Join Date
    Nov 2011
    Posts
    65
    Rep Power
    0

    Default Re: How do I fix this issue?

    Step one, Download eclipse or another good ide

    Step two look for errors and figure out why they are they, if your unsure specificly ask on certain code lines

  4. #4
    m4mm4l is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: How do I fix this issue?

    true, okay so the program has to ask you to enter a word. At the same time it randomly generates a letter. Say you enter "word" and the letter it generates is "r"...If there is 4 or less randomly gen'd letters in the word you enter it only takes away 5 points, but if you enter a word that has no secret letters in it, it takes away 10 points....my problem is, is that I cant figure out how to make it do that. If I enter the secret letter once it says "you win", but if I enter the letter multiple times it doesn't work. (what I have to do is on the PDF attached)

  5. #5
    m4mm4l is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: How do I fix this issue?

    I use Crimsion Editior

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default Re: How do I fix this issue?

    I haven't read your code as it is unformatted and hard to read. In future place [ code ] before and [ /code ] after your code (without the spaces).

    You need to loop over the word entered by the user and compare each char with the secret letter. If it matches increment a count. After that if count is greater than zero subtract 5 points else subtract 10 points. By the way your massive if statement generating the secret letter can be replaced with a single line. Here's a hint:
    Java Code:
    System.out.println((char)(0 + 'a'));
    System.out.println((char)(25 + 'a'));

  7. #7
    m4mm4l is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: How do I fix this issue?

    Thank you sooo much!! it works now. And its my first time programming so I'll keep that in mind. Thanks again!

  8. #8
    m4mm4l is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: How do I fix this issue?

    do you mean like this:

    Java Code:
     // Guess the Secret Letter Game
     // Designed By: Ben Smith
     // November 10th 2011
     // Version: 1.0
     
    import hsa. * ; 
    
    public class BenSmithGuessTheSecretLetterGame{
     public static void main(String[] args){
     Console con = new Console(40,60);
    
     // Variables
     String strMenuSelect;
     String strGuess;
     String strRand;
     String strLetter;
     int intCounter;
     int intCounter2;
     int intPoints;
     int intRand;
     int intLength;
     int intLose;
     int intMaxAlpha;
    
     // Menu and User menu selection
     con.println("Welcome to Guess the Secret Letter Game!!");
     con.println(" *************");
     con.println(" *****************");
     con.println(" ****** ******");
     con.println(" ***** ******");
     con.println(" **** *****");
     con.println(" *****");
     con.println(" *******");
     con.println(" *******");
     con.println(" ********");
     con.println(" *****");
     con.println(" *****");
     con.println(" *****");
     con.println(" *****");
     con.println(" *****");
     con.println("");
     con.println(" ***");
     con.println(" *****");
     con.println(" ***");
    
     // Defaulting Variables
     intCounter = 0; 
    intCounter2= 0;
     intPoints = 50;
     intRand = 0;
     intLose = 0;
     intMaxAlpha = 26;
     strMenuSelect = "";
     strGuess = "";
     strRand = "";
     strLetter = ""; 
    
    // Menu Seleciton
     con.println("Menu");
     con.println("==============");
     con.println("(P)lay Game");
     con.println("(I)nstructions");
     con.println("(Q)uit");
     con.println("Enter you selection here");
     strMenuSelect = con.readLine();
    
     // Generating the number and assigning a lettetr to a number 
    intRand = (int)(Math.random()*26+1);
     if(intRand == 1){
     strRand = ("a");
     }else if(intRand == 2){
     strRand = ("b"); 
    }else if(intRand == 3){
     strRand = ("c"); 
    }else if(intRand == 4){
     strRand = ("d"); 
    }else if(intRand == 5){
     strRand = ("e"); 
    }else if(intRand == 6){
     strRand = ("f"); 
    }else if(intRand == 7){
     strRand = ("g"); 
    }else if(intRand == 8){
     strRand = ("h"); 
    }else if(intRand == 9){
     strRand = ("i"); 
    }else if(intRand == 10){
     strRand = ("j"); 
    }else if(intRand == 11){
     strRand = ("k");
     }else if(intRand == 12){
     strRand = ("l"); 
    }else if(intRand == 13){
     strRand = ("m"); 
    }else if(intRand == 14){
     strRand = ("n"); 
    }else if(intRand == 15){
     strRand = ("o"); 
    }else if(intRand == 16){
     strRand = ("p"); 
    }else if(intRand == 17){
     strRand = ("q"); 
    }else if(intRand == 18){
     strRand = ("r"); 
    }else if(intRand == 19){
     strRand = ("s"); 
    }else if(intRand == 20){
     strRand = ("t"); 
    }else if(intRand == 21){
     strRand = ("u"); 
    }else if(intRand == 22){
     strRand = ("v"); 
    }else if(intRand == 23){
     strRand = ("w"); 
    }else if(intRand == 24){
     strRand = ("x"); 
    }else if(intRand == 25){
     strRand = ("y"); 
    }else if(intRand == 26){
     strRand = ("z");
     }
     con.println(strRand); // Prints the randomly gen'd letter on the main console
    
     // Play Game Code
     if(strMenuSelect.equalsIgnoreCase("P")){
     Console con2 = new Console();
     con2.println("You selected Play Game");
     con2.println("==============");
     con2.println("You currently have 50 points");
     for(intCounter = 0; intCounter <= intLose; intCounter--){ 
    con2.println("Enter a word with the secret letter in it");
     strGuess = con2.readLine();
    
     for(intCounter2 = 0; intCounter2 < strGuess.length(); intCounter2++){
     if(strRand.equals (strGuess)){ 
    strLetter = strGuess.substring(intCounter2, intCounter2+1);
     while(strGuess.equalsIgnoreCase(strRand)){ // Verifys that the guess equals the gen'd letter
     if(strLetter.equalsIgnoreCase(strRand)){ // If the guess equals the gen'd letter then it runs the game code
     intPoints = 0;
     con2.println("YOU WIN!!!");
     break;
     }
     }
     }else if(!strLetter.equalsIgnoreCase(strRand)){
     con2.println("WRONG DEDUCTING 5 POINTS!");
     intPoints = intPoints-5; 
    }
     if(strGuess.equalsIgnoreCase(strRand)){
     intLength = strLetter.length();
     }
    
     if(intPoints < 0){
     con2.println("YOU LOSE!!"); 
    } 
    }
     }
     }
    
     // Instructions
     if(strMenuSelect.equalsIgnoreCase("I")){
     Console con3 = new Console();
     con3.println("You selected Instructions");
     con3.println("How to play");
     con3.println("====================");
     con3.println("You start with 50 points. A secret");
     con3.println("letter will be generated and you have");
     con3.println("to enter a word with that letter in it.");
     con3.println("If the word you enter does not have");
     con3.println("the secret letter then you will lose 10 ");
     con3.println("points. If the word you enter has the ");
     con3.println("letter once or up to 4 times then you ");
     con3.println("lose 5 points. If the word you enter ");
     con3.println("has the letter 5 times or more you win! ");
     con3.println("If your points are 0 or less then you lose.");
     } 
    
    // Quit
     if(strMenuSelect.equalsIgnoreCase("Q")){
     con.println("=============");
     con.println("Thank you for playing Guess the Secret Letter!!");
     con.println("Created By: Ben Smith");
     }
    
     }
     }

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default Re: How do I fix this issue?

    That managed to wrap code tags around it but it is still hard to read due to lack of indentation.

Similar Threads

  1. JSP issue
    By RamaLakshmi in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-21-2011, 01:55 PM
  2. nio issue
    By mawandiadeepak in forum Networking
    Replies: 2
    Last Post: 03-17-2010, 05:23 AM
  3. JSF issue
    By premjo in forum New To Java
    Replies: 0
    Last Post: 02-14-2010, 02:19 PM
  4. Issue
    By FlashNinja in forum New To Java
    Replies: 20
    Last Post: 11-28-2009, 09:44 PM
  5. PDF Box issue
    By jazz2k8 in forum Advanced Java
    Replies: 0
    Last Post: 03-20-2009, 11:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •