Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 58
  1. #21
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Generate an alphabet

    study this code and understand how it works....then I will get back to you

    Java Code:
    char [] alphabet=new char[26];
    		alphabet[0]='a';
    		// fill up alphabet with the 26 letters of the alphabet
    		for(int i=1;i<alphabet.length;i++)
    		{
    			alphabet[i]=(char) (alphabet[i-1]+1);
    		}
    run this in a main programme by itself and have a function print out the contents of alphabet array, and ask yourself how you think it works, then come back and ask questions, dont go too far ahead of yourself

  2. #22
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Question How this function works ..

    It would generate and print out all 26 alphabets.

    (alphabet[i-1]+1);
    What does this do ... i minus 1 then plus one again?

    :confused:

  3. #23
    Anandt88 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by poisson View Post
    It would generate and print out all 26 alphabets.


    What does this do ... i minus 1 then plus one again?

    :confused:
    Hey Poisson,

    Guess U Havn't noticed the code sent by al_Marshy_1981 correctly

    If u notice it is alphabet[i-1]+1

    take the 1st case when i=1, alphabet[1-1]+1 = alphabet[0]+1="ascii" of a+1=b

    thats how its typing all the Alphabet.

  4. #24
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Thumbs up Thanks

    Oh. oh ok.

    Thanks ... didn't relate the ' i ' back with "for(int i=1;i<alphabet.length;i++)", no wonder i was wondering why i would subtract and add one unknowingly, ok, i got it .. little mistake in the understanding there.

    Thanks again Anandt88 !!

  5. #25
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by al_Marshy_1981 View Post
    study this code and understand how it works....then I will get back to you

    Java Code:
    char [] alphabet=new char[26];
    		alphabet[0]='a';
    		// fill up alphabet with the 26 letters of the alphabet
    		for(int i=1;i<alphabet.length;i++)
    		{
    			alphabet[i]=(char) (alphabet[i-1]+1);
    		}
    run this in a main programme by itself and have a function print out the contents of alphabet array, and ask yourself how you think it works, then come back and ask questions, dont go too far ahead of yourself
    That is so Fortranesque or Pascalian at best. Have a look:

    Java Code:
    char[] alphabet= "abcdefghijklmnopqrstuvwxyz".toCharArray();
    kind regards,

    Jos

  6. #26
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Default

    So what's next Al_marshy_81?

  7. #27
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Exclamation There's some problems with my codes and need more help and improvements - READ MORE!

    There's some problems with my codes ... and require more help and improvements to the codes as many features are missing from the game ....

    This is the class i created for the introduction : (BELOW)

    Java Code:
    public class Intro 
    {
    	public String Intro;
    	
    	public Intro(String Intro)
    	{
    		Intro = Intro;
    	[COLOR="Blue"]//[=====================[INTRODUCTION PANEL]========================================================][/COLOR]
    	System.out.println(" Welcome to the FindYourLettersGame  ");
    	System.out.println("Done by Poisson");
            [COLOR="Blue"]//[==================================================================================================][/COLOR]
    
        }
    This is the code I've created for Game Instructions :

    Java Code:
    public class GameInstructions 
    {
    	public String GameInstructions;
    	
    	public GameInstructions(String GameInstructions)
    	{
    		GameInstructions = GameInstructions;
    		[COLOR="Blue"]//[================================================================================================]
    		//This will display the Rules Of The Game[/COLOR]
    		System.out.println("[==================[HOW TO PLAY]==========================================]");
    		System.out.println("- This is a 2 player FindYourWords game!!!"); 
    		System.out.println("- Each Player will be provided with 10 random letters with at least 2 vowels");
    		System.out.println("- Each Player will take turns to enter their word using the 10 Random Letters provided To Them ONLY!!");
    		System.out.println("- The entered word will be checked for its validity, and the Player can try again if He/She enters a valid word");
    		System.out.println("unless The Player Want To Pass Their Turn");
    		System.out.println("- If the player decides to pass, Player 2 will be next to enter in their word");
    		System.out.println("- Game will continue for as many rounds unless a player quit the game");
    		System.out.println("- The scores will be displayed at the end of the game");
    		System.out.println("- The Player with the highest scores will win the game!");
    		System.out.println(" ");
    		System.out.println("[========================================================================]");
    		[COLOR="Blue"]// End Of the Rules Of The Game
    		//[==================================================================================================][/COLOR]
    	}
    }
    This is my overall codes : (Right Below)

    Java Code:
    import java.io
    import java.util.Scanner;
    import java.util.Random;
    public class FindYourLettersGame {
    
    	public static void main(String[] args) {
    [COLOR="Blue"]//[=====================[INTRODUCTION PANEL]========================================================]
    		//This will display the introduction[/COLOR]
    		FindYourLettersGame Intro = new FindYourLettersGame();
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[INITIALISE RANDOM]==========================================================][/COLOR]
    		Random randomPlay = new Random();
    		Scanner scan = new Scanner(System.in);
    [COLOR="Blue"]//[==================================================================================================]
    		//This will display the Instructions Of The Game[/COLOR]
    		FindYourLettersGame GameInstructions = new FindYourLettersGame();
    [COLOR="Blue"]//[=====================[CHECKS LETTERS FOR ITS EXISTENCE IN THE "WORDS.TXT"]========================]	[/COLOR]
    		String wordLog[] = FileUtil.readDictFromFile("words.txt");
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[DECLARE ALL THE REQUIRED VARIABLES FOR THE FINDYOURLETTERS GAME]============]
    		//Array for letters, array for assigned letters score and array for vowels[/COLOR]
    		char[] Letters = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    		int [] alphaScore = {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
    		char[] vowelsFive = {'A', 'E', 'I', 'O', 'U'}; 
    		[COLOR="Blue"]//This is to assign the letters and place it within numbers of 10 ===========================][/COLOR]
    		char[] shuffleLetters = new char[10];
    		int[] randomDigit = new int[31];
    		[COLOR="Blue"]//Initialise playerName input[/COLOR]
    		String playerName = null;
    		[COLOR="Blue"]//Initialise index/position of the elements in the array[/COLOR]
    		int index;
    		[COLOR="Blue"]//Initialise wordInput[/COLOR]
    		String wordInput = null;
    		[COLOR="Blue"]//Initialise word's score[/COLOR]
    		int score4Word = 0;
    		[COLOR="Blue"]//Initialise player's score[/COLOR]
    		int score4Player = 0;
    		[COLOR="Blue"]//Initialise pass and quit[/COLOR]
    		int decides2Pass = @;
    		int decides2Quit = !;
    [COLOR="Blue"]//[================================================================================================][/COLOR]
    		
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[PRINTS OUT "FINDYOURLETTERS" AND "LETTERS FOR PLAYER"]======================][/COLOR]
    			System.out.println("FindYourLetters");
    			[COLOR="Blue"]//Player will be able to enter their name to be refer as in the game=====================][/COLOR]
    			System.out.print("Enter your name: ");
    			playerName = scan.nextLine();
    			[COLOR="Blue"]//Prints out statement "Letters for{the name the player entered earlier}:"===============][/COLOR]
    			System.out.print("Letters for " + (playerName) +": ");
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[POOL OF 10 RANDOM LETTERS WITH AT LEAST 2 VOWELS]===========================]
    			//Ensure that there are at least 2 vowels in the generated words[/COLOR]
    			for (int k = 0; k < 2; k++){
    			index = randomPlay.nextInt(vowelsFive.length);
    			shuffleLetters[k] = vowelsFive[index];
    		}
    			
    		[COLOR="Blue"]//This would produce the ten random letters it's supposed to
    		//This is to initialise "i" and i is less than the length of shuffleLetter and the iterator[/COLOR]
    		for (int i = 0; i < shuffleLetters.length; i++) 
    			{
    			int xx = randomPlay.nextInt(alphaArray.length); 
    			[COLOR="Blue"]//Check whether the above code works[/COLOR] 
    			if (shuffleLetters[i] == '\u0000')
    			{
    				shuffleLetters[i] = alphaArray[xx];
    			}
    			[COLOR="Blue"]//This would print out the letters and I added the function 
    			//Whereby the comma would be printed out for every letter
    			//until the last letter where there would not be any comma[/COLOR]
    			System.out.print(shuffleLetters[i]+ ((i < 9) ? ", " : " " ));
    			}
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[PASS OR QUIT - PLAYER'S CHOICE]=============================================]
    		//Objective Of wordCheck is to count for how many letters in player's input
    		//is the same as the given letters[/COLOR]
    		int wordCheck = 0;
    		int dictCount = 0;
    		[COLOR="Blue"]//Total score for word after checking[/COLOR]
    		score4Word = 0;
    		score4Player = 0;
    		System.out.println("");
    		System.out.print("Enter your word (or @ to pass or ! to quit): " + (wordInput)+ "");
    		wordInput = scan.nextLine();
    		wordInput = wordInput.toUpperCase();
    		[COLOR="Blue"]//This is a For loop to count the no. of letters in player's input
    		//is the same as the given letter[/COLOR]
    		for (int zero =0; zero<wordInput.length(); zero++){
    			for (int g =0; g<shuffleLetters.length; g++){ 
    				if (wordInput.charAt(zero) == shuffleLetters[g]){
    					wordCheck += 1;
    					break;
    				}
    			}
    		}[COLOR="Blue"] // End Of Loop[/COLOR]
    		System.out.println("Total score for word " +": " + score4Word);
    		System.out.println("Total score for " + (playerName) +": " + score4Player);
    [COLOR="Blue"]//[==================================================================================================][/COLOR]
    	}
    }
    Ok, I know how to generate 10 random alphabets with at least 2 vowels

    Do not know how to create the part where 2 players can play such as :

    if (playersTurn == true)
    System.out.println("Letters of player" + playerName + ": " + lettersGiven);
    else
    System.out.println("Letters of player + playerName + ": " + lettersGiven);
    This is the code which I've created to assign scores to those letters, it's a switch statements :

    Java Code:
                    int wordLength = 0;
    		int score = 0;
                    [COLOR="Blue"]//returns integer[/COLOR]
    		wordLength = inputWord.length();
                    [COLOR="Blue"]//perLetter[0] = 'a';[/COLOR]
                    char[] perLetter = inputWord.toUpperCase().toCharArray();
    		
                for (int i = 0 ; i < wordLength; i++)
    		{	
                            [COLOR="Blue"]//convert the letter to upperCase[/COLOR]
    			switch (perLetter[i]) 
    			{
                                    [COLOR="Blue"]// Letters with score = 1[/COLOR]
    				case 'A': case 'E': case 'I': case 'O': case 'U':  
    					score = score + 1; 					
    					break;
    				case 'L': case 'N': case 'R': case 'S': case 'T':  
    					score = score + 1; 
    					break;
                                    [COLOR="Blue"]// Letters with score = 2[/COLOR]
    				case 'D': case 'G':  
    					score = score + 2; 
    					break;
                                    [COLOR="Blue"]// Letters with score = 3[/COLOR]
    				case 'B': case 'C': case 'M': case 'P' :  
    					score = score + 3; 
    					break;
                                    [COLOR="Blue"]// Letters with score = 5[/COLOR]
    				case 'K':  
    					score = score + 5; 
    					break;
                                    [COLOR="Blue"]// Letters with score = 4[/COLOR]
    				case 'F': case 'H': case 'V': case 'W': case 'Y':  
    					score = score + 4;
    					break;
                                    [COLOR="Blue"]// Letters with score = 8[/COLOR]
    				case 'J': case 'X':  
    					score = score + 8; 
    					break;
                                    [COLOR="Blue"]// Letters with score = 10[/COLOR]
    				case 'Q': case 'Z':  
    					score = score + 10;
    					break;
    			default:  break;			
    			}/**/					
    		}
    This is the code I've created to decides who win ... all of this codes above are not yet insert into the main code as it would mess it up ... just putting the pieces of different functions together :

    Java Code:
                    [COLOR="Blue"]//Initialise winner[/COLOR]
                    String winner = "";
    if (score1 > score2)
    			winner = "Player 1 has won!";
    		if (score2 > score1)
    			winner = "Player 2 has won!";
    		if (score1 == score2)
    			winner = "It is a Draw for both players.";
    		winner = "Total Score of Player 1:  " + score1 + "\n" +
    			"Total Score of Player 2:  " + score2 + "\n" + winner;
    		return winner;		
    	}

    :mad:I asked this question some 2 weeks ago ... tried to asked more abt what the codes other users posted meant as I'm still learning Java bit by bit, but to no avail ... deadline's tmr, not much time ... so I just want to get some features of the game done, so as not to get that bad of a grade.

    :confused: :( :confused:

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Comment on the default: in switch. Do you ever expect it to be called? If not add a println() to say that was called and with what value. That would show a logic problem since you never expected it.

  9. #29
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Smile Abt the switch statement, thx!

    Java Code:
    [COLOR="Blue"]//If it does not match any case ...[/COLOR]
    default: System.out.println("Invalid");
             
    break;
    }
    like this?

    :) thx

  10. #30
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Almost. Better if you show what's wrong:
    System.out.println("Invalid: " + perLetter[i]);

  11. #31
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Thumbs up oh, forgot that too, hehe, thanks Norm!

    Java Code:
    default : System.out.println("Invalid" + perLetter[i]););
    ok, thx, forgotten abt the error! thx!!

    ;)

  12. #32
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Question The classes of Intro and GameInstructions does not print out

    Java Code:
    import java.io
    import java.util.Scanner;
    import java.util.Random;
    public class FindYourLettersGame {
    
    	public static void main(String[] args) {
    //[=====================[INTRODUCTION PANEL]========================================================]
    		//This will display the introduction
    		FindYourLettersGame Intro = new FindYourLettersGame();
    //[==================================================================================================]
    //[=====================[INITIALISE RANDOM]==========================================================]
    		Random randomPlay = new Random();
    		Scanner scan = new Scanner(System.in);
    //[==================================================================================================]
    		//This will display the Instructions Of The Game
    		FindYourLettersGame GameInstructions = new FindYourLettersGame();
    //[=====================[CHECKS LETTERS FOR ITS EXISTENCE IN THE "WORDS.TXT"]========================]	
    		String wordLog[] = FileUtil.readDictFromFile("words.txt");
    //[==================================================================================================]
    The part where :
    //This will display the introduction
    FindYourLettersGame Intro = new FindYourLettersGame();
    and :
    //This will display the Instructions Of The Game
    FindYourLettersGame GameInstructions = new GameInstructions();
    could not be printed out, what's my problem?

    I've created the various classes for Intro and GameInstructions from my previous posted reply ...

    My deadline's in 5 hours time b4 i submit my full codes, soo

    Any idea?

  13. #33
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Question I want to create a method 4 getting the 10 random letters but there's problem,help?!!

    Java Code:
    private static String GetShuffleLetters() 
    	{
    		[COLOR="Blue"]// TODO Auto-generated method stub[/COLOR]
    		
    		[COLOR="Blue"]//Code to display random letters
    		//Ensure that there are at least 2 vowels in the generated words[/COLOR]
    		for (int k = 0; k < 2; k++){
    		index = randomGen.nextInt(Vowels.length);
    		shuffleLetter[k] = Vowels[index];
    	}
    		
    	[COLOR="Blue"]//This would produce the ten random letters it's supposed to
    	//This is to initialise "i" and i is less than the length of shuffleLetter and the iterator[/COLOR]
    			for (int i = 0; i < shuffleLetter.length; i++) 
    			{
    				int xx = randomGen.nextInt(alphaArray.length); 
    				[COLOR="Blue"]//Check whether the above code works[/COLOR] 
    				if (shuffleLetter[i] == '\u0000')
    				{
    					shuffleLetter[i] = alphaArray[xx];
    				}
    				[COLOR="Blue"]//This would print out the letters and I added the function 
    				//Whereby the comma would be printed out for every letter
    				//until the last letter where there would not be any comma[/COLOR]
    				System.out.print(shuffleLetter[i]+ ((i < 9) ? ", " : " " ));
    			}
    		
    		}return GetShuffleLetters;
    
    		
    	}
    		
    		return null;
    	}
    }
    This is the method that I think I've created , but it states that GetShuffleLetters cannot resolved to a type and the String is "Syntax or token "String", @ expected ...

    I'm not good with methods and constructors, anyone have any idea?!!!


    Java Code:
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    import java.util.Random;
    import java.util.Scanner;
    public class  FindYourLettersGame{
    
    	public static void main(String[] args) {
    [COLOR="Blue"]//[=====================[INTRODUCTION PANEL]========================================================][/COLOR]
    		FindYourLettersGame Intro = new FindYourLettersGame();
    		System.out.println(Intro);
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[INITIALISE RANDOM]==========================================================][/COLOR]
    		Random randomGen = new Random();
    		Scanner scan = new Scanner(System.in);
    [COLOR="Blue"]//[==================================================================================================][/COLOR]
    
    [COLOR="Blue"]//[=====================[CHECKS LETTERS FOR ITS EXISTENCE IN THE "WORDS.TXT"]========================]	[/COLOR]
    		String wordLog[] = FileUtil.readDictFromFile("words.txt");
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[ARRAY FOR LETTERS, ARRAY FOR ASSIGNED LETTER SCORE AND VOWELS]==============][/COLOR]
    		char [] alphaArray = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    		int [] alphaScore = {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
    		char[] Vowels = {'a', 'e', 'i', 'o', 'u'}; 
    		[COLOR="Blue"]//This is to assign the letters and place it within numbers of 10 ===========================][/COLOR]
    		char[] shuffleLetter = new char[10];
    		int[] randomInteger = new int[31];
    		[COLOR="Blue"]//Initialise playerName and playerName2 input
                    // in order to get "Letters for Player "playerName": vice versa[/COLOR]
    		String playerName = null;
    		String playerName2 = null;
    		[COLOR="Blue"]//Initialise index/position of the elements in the array[/COLOR]
    		int index;
    		[COLOR="Blue"]//Initialise choice Input[/COLOR]
    		int choice = 0;
    		[COLOR="Blue"]//Initialise wordInput[/COLOR]
    		String wordInput = "&";
    		[COLOR="Blue"]//Initialise the boolean to check  word validity, make valid equals to false first[/COLOR]
    		boolean valid = false;
    		[COLOR="Blue"]//Initialise InputStreamReader to covert bytes into character stream[/COLOR]
    		InputStreamReader input = new InputStreamReader(System.in); 
    		[COLOR="Blue"]//InputStreamReader is being wrapped in here == Reads text from char stream[/COLOR]
    		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    		
    [COLOR="Blue"]//[==================================================================================================][/COLOR]
    		
    		[COLOR="Blue"]//While comparing the wordInput to quit or not ...[/COLOR]
    		while (wordInput.compareTo("!") > 0) {
    			
                            [COLOR="Blue"]// Get the random letters[/COLOR]
    			wordInput = getshuffleLetters();
    			[COLOR="Blue"]//try and catch[/COLOR]
    			try {
    			
                                    [COLOR="Blue"]// Menu to select what do the players want to do[/COLOR]
    				System.out.println("Menu :");
    				System.out.println("\t9 - Enter your names");
    				System.out.println("\t8  - Continue! ^______^");
    				System.out.println("\t@  - Pass ^______^");
    				System.out.println("\t! - Exit -_-");
    				[COLOR="Blue"]//Prompts user to enter their choice[/COLOR]
    				System.out.println("Please enter your choice : ");
    				choice = scan.nextInt();
    				
    				if (choice == 9) 
    				{
    					[COLOR="Blue"]// Choice 1 actions displays!
    					//enter name[/COLOR]
    					System.out.println("Enter your name: ");
    					playerName=scan.nextLine();
                                            [COLOR="Blue"]//Do not know how to make it such that
                                            //Player one types first then followed by 
                                            //Player two ... damn >.<[/COLOR]
    					System.out.println("Enter your name: ");
    					playerName2=scan.nextLine();
    				} else if (choice == '@') 
    				{
    					continue;
    				} else if (choice == '!') 
    				{
    					[COLOR="Blue"]// Option 'Exit' actions here[/COLOR]
    					System.out.println("You have chosen to exit.\nThe game will exit now.");
    				} else if (choice != 9 || choice != 8 || choice != '@'|| choice != '!')
    				{
    					[COLOR="Blue"]// Invalid option[/COLOR]
    					System.out.println("**Invalid choice, please choose again.**");
    				}
    				else 
    				{
    				} if (choice == 8) {
    					// Choice 2 actions displays!
    					System.out.println("Letters for player " +(playerName)+ ":  " +shuffleLetter);
    					
    				} else {
    					System.out.println("Letters for player " +(playerName2)+ ":  " +shuffleLetter);
    				}
    				[COLOR="Blue"]//To stop=========================================================+[/COLOR]
    				break;
    	} catch (Exception e) {
    			[COLOR="Blue"]// catch \n of the scan error exception===============================+[/COLOR]
    			String junk = scan.nextLine();
    			System.out.println(" ** ERROR!!! There's no such choice. ** ");
    			System.out.println(" ** Please try again!!! ** ");
    	}
    			
    [COLOR="Blue"]//[=====================[PRINTS OUT "FINDYOURLETTERS" AND "LETTERS FOR PLAYER"]======================][/COLOR]
    			System.out.println("FindYourLetters");
    [COLOR="Blue"]//[==================================================================================================]
    //[=====================[POOL OF 10 RANDOM LETTERS!!!]===============================================]
    			
    //[==================================================================================================]
    //[=====================[PASS OR QUIT - PLAYER'S CHOICE]=============================================][/COLOR]
    		System.out.println("");
    		System.out.println("Enter your word (or ‘@’ to pass or ‘!’ to quit): ");
    [COLOR="Blue"]//[==================================================================================================][/COLOR]
    
    
    	private static String getshuffleLetters() 
    	{
    		// TODO Auto-generated method stub
    		
    		[COLOR="Blue"]//Code to display random letters
    		//Ensure that there are at least 2 vowels in the generated words[/COLOR]
    		for (int k = 0; k < 2; k++){
    		index = randomGen.nextInt(Vowels.length);
    		shuffleLetter[k] = Vowels[index];
    	}
    		
    	[COLOR="Blue"]//This would produce the ten random letters it's supposed to
    	//This is to initialise "i" and i is less than the length of shuffleLetter and the iterator[/COLOR]
    			for (int i = 0; i < shuffleLetter.length; i++) 
    			{
    				int xx = randomGen.nextInt(alphaArray.length); 
    				//Check whether the above code works 
    				if (shuffleLetter[i] == '\u0000')
    				{
    					shuffleLetter[i] = alphaArray[xx];
    				}
    				[COLOR="Blue"]//This would print out the letters and I added the function 
    				//Whereby the comma would be printed out for every letter
    				//until the last letter where there would not be any comma[/COLOR]
    				System.out.print(shuffleLetter[i]+ ((i < 9) ? ", " : " " ));
    			}
    		
    		}return getshuffleLetters;
    
    		
    	}
    		
    		
    	}
    }
    This is my overall code in my Java Eclipse and Notepad++, i wanted to place the method below and it would act as a shortcut in the while loop :

    while (wordInput.compareTo("!") > 0) {

    wordInput = GetShuffleLetters();

    try { ...
    Errors I received from the above overall codes ...
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    The method getshuffleLetters() is undefined for the type FindYourLettersGame
    Syntax error on token "String", @ expected
    getshuffleLetters cannot be resolved to a type
    Syntax error, insert "enum Identifier" to complete EnumHeaderName
    Syntax error, insert "EnumBody" to complete BlockStatement

    at FindYourLettersGame.main(FindYourLettersGame.java: 55)
    I'm terribly suck in Java, still determined to get the answer even after submitting it in half hour's time and how to improve my codes further even though my Java project is expected to get a "Fail" this week ... =_= at least gave my best shot at it, feels good :)



    :(:(:(
    Last edited by poisson; 06-14-2010 at 04:16 PM. Reason: Forgot some codes

  14. #34
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Sorry, I'm not familiar with the program that generates the error messages you've posted.
    When I use javac and have errors I get:
    angMan2.java:193: cannot find symbol
    symbol : variable val
    location: class HangMan2
    obj.method(val);
    ^
    HangMan2.java:193: cannot find symbol
    symbol : variable obj
    location: class HangMan2
    obj.method(val);
    ^
    HangMan2.java:194: cannot find symbol
    symbol : variable val
    location: class HangMan2
    val = 22;
    ^
    HangMan2.java:7: warning: [serial] serializable class HangMan2 has no definition of serialVersionUID
    public class HangMan2 extends JFrame implements ActionListener{
    ^
    3 errors
    1 warning
    These have the line number and shows the source line itself with the error.

    Your error messages appear to have been edited.

  15. #35
    poisson is offline Member
    Join Date
    May 2010
    Location
    Singapore
    Posts
    31
    Rep Power
    0

    Arrow Ok, i will look into that matter.

    angMan2.java:193: cannot find symbol
    symbol : variable val
    location: class HangMan2
    obj.method(val);
    ^
    HangMan2.java:193: cannot find symbol
    symbol : variable obj
    location: class HangMan2
    obj.method(val);
    ^
    HangMan2.java:194: cannot find symbol
    symbol : variable val
    location: class HangMan2
    val = 22;
    ^
    HangMan2.java:7: warning: [serial] serializable class HangMan2 has no definition of serialVersionUID
    public class HangMan2 extends JFrame implements ActionListener{
    ^
    3 errors
    1 warning
    These have the line number and shows the source line itself with the error.

    Your error messages appear to have been edited.
    Ok, i will look into that matter first, hehe.

  16. #36
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by JosAH View Post
    That is so Fortranesque or Pascalian at best. Have a look:

    Java Code:
    char[] alphabet= "abcdefghijklmnopqrstuvwxyz".toCharArray();
    kind regards,

    Jos
    maybe so but it shows more whats going on than that charArray function from a learners point of view

  17. #37
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Poisson if you have a function that generates 26 letters of the alphabet, good. now you need to assign scores to each letter, how do you think you will accomplish this? think a class to store scoring information

  18. #38
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by al_Marshy_1981 View Post
    maybe so but it shows more whats going on than that charArray function from a learners point of view
    That line show exactly what is goig on: a String is converted to a character array; the method name even literally say so. Your code is just Fortranesque and you really have to pay attention if you want to figure out what is going on.

    kind regards,

    Jos

  19. #39
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Your code is just Fortranesque
    Never heard that term. I coded fortran years ago and don't get the connection. Is it something that they teach in school in a negative way?
    Could you elaborate please.
    Thanks.

  20. #40
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Norm View Post
    Never heard that term. I coded fortran years ago and don't get the connection. Is it something that they teach in school in a negative way?
    Could you elaborate please.
    Thanks.
    Yep, you have that right; the term means 'Fortran-like', just like 'Pascalian' which means 'Pascal-like'. Most of the OO beginners program in that way: mechanical, arrays, nested loops and very much a spaghetti control flow. e.g. building a character array that contains just the characters 'A', 'B', 'C' etc. is simply Fortranesque because you couldn't do it another/better way in that language.

    kind regards,

    Jos

    ps. I used to program in Fortran IV and Fortran 77 and Pascal too, but I got over it ;-)

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. What are you using to write your code?
    By CaptainMorgan in forum New To Java
    Replies: 991
    Last Post: 08-22-2014, 06:35 PM
  2. How To Write Unmaintainable Code
    By tim in forum Forum Lobby
    Replies: 2
    Last Post: 02-07-2010, 09:19 PM
  3. Can I write code in 2 different files ?
    By fartek in forum New To Java
    Replies: 2
    Last Post: 02-14-2009, 03:48 PM
  4. Help me to write a secure code
    By Bhavis in forum Advanced Java
    Replies: 4
    Last Post: 01-21-2009, 06:06 AM
  5. How to write code comments
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:06 PM

Posting Permissions

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