Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    I am having a file StringGame.java

    At school, my teacher guided me to open TERMINAL then type " javac StringGame.java " to create the StringGame.html file. However, after I edited the *.java file by changing some code. Then I am not be able to create the StringGame.html

    Anyone knows how to do it ?:confused:
    Offline

    2
    ReputationRep:
    (Original post by ahieuheo74)
    I am having a file StringGame.java

    At school, my teacher guided me to open TERMINAL then type " javac StringGame.java " to create the StringGame.html file. However, after I edited the *.java file by changing some code. Then I am not be able to create the StringGame.html

    Anyone knows how to do it ?:confused:
    HTML? Surely you mean .class
    And perhaps a good first step is to tell us what changes you actually made to your code.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by Chrosson)
    HTML? Surely you mean .class
    And perhaps a good first step is to tell us what changes you actually made to your code.
    Yes. it is. I don't know what parts, do I need to paste the long code in here ? you please check it for me ? I am surely compiled successfully.
    • Thread Starter
    Offline

    0
    ReputationRep:
    import java.lang.*;
    import javax.swing.*;
    import java.util.*;

    public final class StringGame {
    /**
    * This class method called removeDoubletons that takes a String as an
    * argument and returns a String where any doubletons have been removed
    * from the original String. A doubleton occurs if two consecutive letters
    * are the same.
    *@param guessword1 is a String
    *@return remove a surplus character if they are the same.
    * e.g. crackker will be " cracker "
    */
    public static String removeDoubletons (String guessword1)
    {
    StringBuffer removedouble = new StringBuffer(guessword1);

    for(int i=0; i < removedouble.length()-1; i++) {
    if(removedouble.charAt(i+1) == removedouble.charAt(i)){
    removedouble.deleteCharAt(i);
    }
    }
    return removedouble.toString();

    } // end of method removeDoubletons

    /**
    * takes a String as its parameter. The method returns a string where
    * all characters in the source string are shifted to the right by a
    * random amount between 2 and the length of the string.
    *@param guessword2 is a String
    *@return random move position - a String with move by a number of steps to
    *the right
    *e.g cracker will be " ercrack "
    */
    public static String randomMove (String guessword2){
    Random randomCreate = new Random();
    int randomNumber = 0;
    randomNumber = randomCreate.nextInt(guessword2. length()-2);
    randomNumber = randomNumber + 2;

    String firsthalf, resthalf;

    firsthalf = guessword2.substring(guessword2. length()-randomNumber, guessword2.length());
    resthalf = guessword2.substring(0, guessword2.length()-randomNumber);

    String guesswordMoved = firsthalf + resthalf;

    return guesswordMoved.toString();
    } // end of method randomMove

    /**
    * takes a string as its parameter.
    * The method goes through the String sequentially and every time
    * a vowel is encountered the vowel is removed from the string
    *@param guessword3 is a String
    *@return a String without any Vowels
    * e.g cracker will be " cr ck r "
    */
    public static String removeVowels (String guessword3){

    char letter;
    StringBuffer del = new StringBuffer(guessword3);

    for (int i=0; i < del.length(); i++){
    letter = del.charAt(i);

    if (letter == 'a'|| letter == 'A'|| letter == 'e'|| letter == 'E'|| letter == 'o'|| letter == 'O'|| letter == 'i'|| letter == 'I'|| letter == 'u'|| letter == 'U') {
    del.deleteCharAt(i);
    i=0;
    }
    }
    return del.toString();
    } // end of method removeVowels

    /**
    * This class method called endGame that takes two Strings as
    * arguments and give two outputs. If users enter the word matched to
    * the original word then a message dialog appears "You guessed correctly"
    * Otherwise, appears "You guessed incorrectly."
    *@param rightword, wrongword are Strings
    *@return remove a surplus character if they are the same.
    *
    */

    public static Boolean endGame(String rightword, String wrongword)
    {
    Boolean h = true;
    if (rightword.compareToIgnoreCase(w rongword) == 0)
    {JOptionPane.showMessageDialog(n ull, "You guessed correctly.");
    h = false; }
    else { JOptionPane.showMessageDialog(nu ll, "You guessed incorrectly.");
    h = false;
    } return h;
    }// end of method endGame

    /**
    * takes a string as its parameter.
    * The method goes through the String sequentially and every time
    * a character is replaced by a dash "-"
    *@param dashword is a String
    *@return a String to dashes which number of characters equal to number
    * dashes.
    * e.g cracker will be "- - - - - - - "
    */

    public static String codeWord(String dashword)
    {
    String dash = "";

    for (int i=0; i<dashword.length();i++){
    dash = dash + "-";
    } return dash.toString();
    }// end of method codeWord

    /**
    * takes a string as its parameter.
    * The method goes through the String sequentially and first time
    * a character is matched to the character from original String
    * it will then replace the dash
    *@param match1, guess1, dash1 are Strings
    *@return new String with matched characters, if not still dashes.
    *
    * e.g cracker, enter "c" it will be "c - - c - - - "
    */
    public static String ReplaceDash(String match1, String guess1, String dash1)
    { StringBuffer match = new StringBuffer (dash1);
    for (int i=0; i<guess1.length(); i++) {
    if (match1.charAt(0) == guess1.charAt(i)) {
    match.replace(i, i+1, match1);
    }
    } return guess1=match.toString();

    }
    /**
    *
    * Method : main
    *
    */
    public static void main (String[] args) {
    // Collect the random word
    String guessword;
    // Classified the letter of the word
    int selection;

    do {
    guessword = JOptionPane.showInputDialog(null ,"Please enter a word.");
    } while (guessword.length()<=3);
    String guessword1 = new String(guessword);
    selection = JOptionPane.showConfirmDialog(nu ll,"Do you want to run method 1 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCE L_OPTION);
    if (selection==JOptionPane.YES_OPTI ON) {
    guessword1 = removeDoubletons(guessword1);
    System.out.println(guessword1);
    }
    String guessword2 = new String(guessword);
    int selection2;
    selection2 = JOptionPane.showConfirmDialog(nu ll,"Do you want to run method 2 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCE L_OPTION);
    if (selection2==JOptionPane.YES_OPT ION){
    guessword2 = randomMove(guessword2);
    System.out.println(guessword2);
    }
    String guessword3 = new String(guessword);
    int selection3;
    selection3 = JOptionPane.showConfirmDialog(nu ll,"Do you want to run method 3 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCE L_OPTION);
    if (selection3==JOptionPane.YES_OPT ION){
    guessword3 = removeVowels(guessword3);
    System.out.println(guessword3);
    }

    String guesstwice = " ";
    Boolean expression = true;

    String unknown = codeWord(guessword);

    while (expression) {
    guesstwice = JOptionPane.showInputDialog(null , unknown=ReplaceDash(guesstwice.t oLowerCase(), guessword.toLowerCase(), unknown) + "\nPlease enter a single chracter, or a word as your final guess.");
    if (guesstwice.length()>1) {
    expression = endGame(guesstwice, guessword1);
    }
    }

    }// end of main method

    } // end of class StringGame


    also, please guys kindly check the code for me. Last MessageDialog, I enter just only one line : " Please enter a single chracter, or a word as your final guess. " but it appears twice. if you guys have Emacs or Esclipe please kindly check it now. I need it ASAP.
    Offline

    1
    ReputationRep:
    (Original post by ahieuheo74)
    import java.lang.*;
    import javax.swing.*;
    import java.util.*;
    ....
    Firstly i really hope that copying and pasting that code is what caused the horrible format if not you should really read up on coding guidelines.

    Secondly that code does not compile as there are around 40 Spaces in variable names / keywords such as "nu ll" should be null (search through there are lots more)

    Lastly to be frank your logic is flawed for the display box you are showing, is this a uni assignment?
    Offline

    1
    ReputationRep:
    Also just read that this is in ubuntu type "java --version" to find out what version is installed
    Offline

    2
    ReputationRep:
    (Original post by mprules)
    Firstly i really hope that copying and pasting that code is what caused the horrible format if not you should really read up on coding guidelines.

    Secondly that code does not compile as there are around 40 Spaces in variable names / keywords such as "nu ll" should be null (search through there are lots more)

    Lastly to be frank your logic is flawed for the display box you are showing, is this a uni assignment?
    I think it's the forum software which puts in spaces in any runs of text longer than 30 characters. Also it probably strips out whitespace, as html does that in any case.

    Is this better?

    Code:
    
    import java.lang.*;
    import javax.swing.*;
    import java.util.*;
    
    	public final class StringGame {
    	/**
    	* This class method called removeDoubletons that takes a String as an
    	* argument and returns a String where any doubletons have been removed
    	* from the original String. A doubleton occurs if two consecutive letters
    	* are the same.
    	*@param guessword1 is a String
    	*@return remove a surplus character if they are the same.
    	* e.g. crackker will be " cracker "
    	*/
    	public static String removeDoubletons (String guessword1) {
    		StringBuffer removedouble = new StringBuffer(guessword1);
    
    		for(int i=0; i < removedouble.length()-1; i++) {
    			if(removedouble.charAt(i+1) == removedouble.charAt(i)) {
    				removedouble.deleteCharAt(i);
    			}
    		}
    		return removedouble.toString();
    
    	} // end of method removeDoubletons
    
    	/**
    	* takes a String as its parameter. The method returns a string where
    	* all characters in the source string are shifted to the right by a
    	* random amount between 2 and the length of the string.
    	*@param guessword2 is a String
    	*@return random move position - a String with move by a number of steps to
    	*the right
    	*e.g cracker will be " ercrack "
    	*/
    	public static String randomMove (String guessword2) {
    		Random randomCreate = new Random();
    		int randomNumber = 0;
    		randomNumber = randomCreate.nextInt(guessword2.length()-2);
    		randomNumber = randomNumber + 2;
    
    		String firsthalf, resthalf;
    
    		firsthalf = guessword2.substring(guessword2.length()-randomNumber, guessword2.length());
    		resthalf = guessword2.substring(0, guessword2.length()-randomNumber);
    
    		String guesswordMoved = firsthalf + resthalf;
    
    		return guesswordMoved.toString();
    	} // end of method randomMove
    
    	/**
    	* takes a string as its parameter.
    	* The method goes through the String sequentially and every time
    	* a vowel is encountered the vowel is removed from the string
    	*@param guessword3 is a String
    	*@return a String without any Vowels
    	* e.g cracker will be " cr ck r "
    	*/
    	public static String removeVowels (String guessword3){
    
    		char letter;
    		StringBuffer del = new StringBuffer(guessword3);
    
    		for (int i=0; i < del.length(); i++) {
    			letter = del.charAt(i);
    
    			if (letter == 'a'|| letter == 'A'|| letter == 'e'|| letter == 'E'|| letter == 'o'|| letter == 'O'|| letter == 'i'|| letter == 'I'|| letter == 'u'|| letter == 'U') {
    				del.deleteCharAt(i);
    				i=0;
    			}
    		}
    		return del.toString();
    	} // end of method removeVowels
    
    	/**
    	* This class method called endGame that takes two Strings as
    	* arguments and give two outputs. If users enter the word matched to
    	* the original word then a message dialog appears "You guessed correctly"
    	* Otherwise, appears "You guessed incorrectly."
    	*@param rightword, wrongword are Strings
    	*@return remove a surplus character if they are the same.
    	*
    	*/
    
    	public static Boolean endGame(String rightword, String wrongword) {
    		Boolean h = true;
    		if (rightword.compareToIgnoreCase (wrongword) == 0) {
    			JOptionPane.showMessageDialog (null, "You guessed correctly.");
    			h = false;
    		} else {
    			JOptionPane.showMessageDialog( null, "You guessed incorrectly.");
    			h = false;
    		}
    		return h;
    	}// end of method endGame
    
    	/**
    	* takes a string as its parameter.
    	* The method goes through the String sequentially and every time
    	* a character is replaced by a dash "-"
    	*@param dashword is a String
    	*@return a String to dashes which number of characters equal to number
    	* dashes.
    	* e.g cracker will be "- - - - - - - "
    	*/
    
    	public static String codeWord(String dashword) {
    		String dash = "";
    
    		for (int i=0; i<dashword.length();i++) {
    			dash = dash + "-";
    		} return dash.toString();
    	}// end of method codeWord
    
    	/**
    	* takes a string as its parameter.
    	* The method goes through the String sequentially and first time
    	* a character is matched to the character from original String
    	* it will then replace the dash
    	*@param match1, guess1, dash1 are Strings
    	*@return new String with matched characters, if not still dashes.
    	*
    	* e.g cracker, enter "c" it will be "c - - c - - - "
    	*/
    	public static String ReplaceDash(String match1, String guess1, String dash1) {
    		StringBuffer match = new StringBuffer (dash1);
    		for (int i=0; i<guess1.length(); i++) {
    			if (match1.charAt(0) == guess1.charAt(i)) {
    				match.replace(i, i+1, match1);
    			}
    		} return guess1=match.toString();
    
    	}
    	/**
    	*
    	* Method : main
    	*
    	*/
    	public static void main (String[] args) {
    		// Collect the random word
    		String guessword;
    		// Classified the letter of the word
    		int selection;
    
    		do {
    			guessword = JOptionPane.showInputDialog(null,"Please enter a word.");
    		} while (guessword.length()<=3);
    		String guessword1 = new String(guessword);
    		selection = JOptionPane.showConfirmDialog(null,"Do you want to run method 1 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCEL_OPTION);
    		if (selection==JOptionPane.YES_OPTION) {
    			guessword1 = removeDoubletons(guessword1);
    			System.out.println(guessword1) ;
    		}
    		String guessword2 = new String(guessword);
    		int selection2;
    		selection2 = JOptionPane.showConfirmDialog(null,"Do you want to run method 2 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCEL_OPTION);
    		if (selection2==JOptionPane.YES_OPTION) {
    			guessword2 = randomMove(guessword2);
    			System.out.println(guessword2) ;
    		}
    		String guessword3 = new String(guessword);
    		int selection3;
    		selection3 = JOptionPane.showConfirmDialog(null,"Do you want to run method 3 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCEL_OPTION);
    		if (selection3==JOptionPane.YES_OPTION) {
    			guessword3 = removeVowels(guessword3);
    			System.out.println(guessword3) ;
    		}
    
    		String guesstwice = " ";
    		Boolean expression = true;
    
    		String unknown = codeWord(guessword);
    
    		while (expression) {
    			guesstwice = JOptionPane.showInputDialog(null, unknown=ReplaceDash(guesstwice .toLowerCase(), guessword.toLowerCase(), unknown) + "\nPlease enter a single chracter, or a word as your final guess.");
    			if (guesstwice.length()>1) {
    				expression = endGame(guesstwice, guessword1);
    			}
    		}
    
    	}// end of main method
    
    } // end of class StringGame
    
    
    
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by mprules)
    Firstly i really hope that copying and pasting that code is what caused the horrible format if not you should really read up on coding guidelines.

    Secondly that code does not compile as there are around 40 Spaces in variable names / keywords such as "nu ll" should be null (search through there are lots more)

    Lastly to be frank your logic is flawed for the display box you are showing, is this a uni assignment?
    OMG you're right. I would paste it to *.txt file then attach here. Thanks for advice. I know that the message dialog is a bit fault because it is duplicate lines. I cannot know how to get rid of it. This is an assignment for 1st year in PROGRAM DESIGN. I haven't studied JAVA before..really get stuck sometimes. My lecturer teaches so fast

    (Original post by mprules)
    Also just read that this is in ubuntu type "java --version" to find out what version is installed
    I actually asked my friend to use Eclipse 3.5 to create HTML file but please kindly guide me how to do it... still haven't got any idea he did it for me at his home.

    (Original post by alex-hs)
    I think it's the forum software which puts in spaces in any runs of text longer than 30 characters. Also it probably strips out whitespace, as html does that in any case.

    Is this better?

    Code:
    
    import java.lang.*;
    import javax.swing.*;
    import java.util.*;
    
    	public final class StringGame {
    	/**
    	* This class method called removeDoubletons that takes a String as an
    	* argument and returns a String where any doubletons have been removed
    	* from the original String. A doubleton occurs if two consecutive letters
    	* are the same.
    	*@param guessword1 is a String
    	*@return remove a surplus character if they are the same.
    	* e.g. crackker will be " cracker "
    	*/
    	public static String removeDoubletons (String guessword1) {
    		StringBuffer removedouble = new StringBuffer(guessword1);
    
    		for(int i=0; i < removedouble.length()-1; i++) {
    			if(removedouble.charAt(i+1) == removedouble.charAt(i)) {
    				removedouble.deleteCharAt(i);
    			}
    		}
    		return removedouble.toString();
    
    	} // end of method removeDoubletons
    
    	/**
    	* takes a String as its parameter. The method returns a string where
    	* all characters in the source string are shifted to the right by a
    	* random amount between 2 and the length of the string.
    	*@param guessword2 is a String
    	*@return random move position - a String with move by a number of steps to
    	*the right
    	*e.g cracker will be " ercrack "
    	*/
    	public static String randomMove (String guessword2) {
    		Random randomCreate = new Random();
    		int randomNumber = 0;
    		randomNumber = randomCreate.nextInt(guessword2.length()-2);
    		randomNumber = randomNumber + 2;
    
    		String firsthalf, resthalf;
    
    		firsthalf = guessword2.substring(guessword2.length()-randomNumber, guessword2.length());
    		resthalf = guessword2.substring(0, guessword2.length()-randomNumber);
    
    		String guesswordMoved = firsthalf + resthalf;
    
    		return guesswordMoved.toString();
    	} // end of method randomMove
    
    	/**
    	* takes a string as its parameter.
    	* The method goes through the String sequentially and every time
    	* a vowel is encountered the vowel is removed from the string
    	*@param guessword3 is a String
    	*@return a String without any Vowels
    	* e.g cracker will be " cr ck r "
    	*/
    	public static String removeVowels (String guessword3){
    
    		char letter;
    		StringBuffer del = new StringBuffer(guessword3);
    
    		for (int i=0; i < del.length(); i++) {
    			letter = del.charAt(i);
    
    			if (letter == 'a'|| letter == 'A'|| letter == 'e'|| letter == 'E'|| letter == 'o'|| letter == 'O'|| letter == 'i'|| letter == 'I'|| letter == 'u'|| letter == 'U') {
    				del.deleteCharAt(i);
    				i=0;
    			}
    		}
    		return del.toString();
    	} // end of method removeVowels
    
    	/**
    	* This class method called endGame that takes two Strings as
    	* arguments and give two outputs. If users enter the word matched to
    	* the original word then a message dialog appears "You guessed correctly"
    	* Otherwise, appears "You guessed incorrectly."
    	*@param rightword, wrongword are Strings
    	*@return remove a surplus character if they are the same.
    	*
    	*/
    
    	public static Boolean endGame(String rightword, String wrongword) {
    		Boolean h = true;
    		if (rightword.compareToIgnoreCase (wrongword) == 0) {
    			JOptionPane.showMessageDialog (null, "You guessed correctly.");
    			h = false;
    		} else {
    			JOptionPane.showMessageDialog( null, "You guessed incorrectly.");
    			h = false;
    		}
    		return h;
    	}// end of method endGame
    
    	/**
    	* takes a string as its parameter.
    	* The method goes through the String sequentially and every time
    	* a character is replaced by a dash "-"
    	*@param dashword is a String
    	*@return a String to dashes which number of characters equal to number
    	* dashes.
    	* e.g cracker will be "- - - - - - - "
    	*/
    
    	public static String codeWord(String dashword) {
    		String dash = "";
    
    		for (int i=0; i<dashword.length();i++) {
    			dash = dash + "-";
    		} return dash.toString();
    	}// end of method codeWord
    
    	/**
    	* takes a string as its parameter.
    	* The method goes through the String sequentially and first time
    	* a character is matched to the character from original String
    	* it will then replace the dash
    	*@param match1, guess1, dash1 are Strings
    	*@return new String with matched characters, if not still dashes.
    	*
    	* e.g cracker, enter "c" it will be "c - - c - - - "
    	*/
    	public static String ReplaceDash(String match1, String guess1, String dash1) {
    		StringBuffer match = new StringBuffer (dash1);
    		for (int i=0; i<guess1.length(); i++) {
    			if (match1.charAt(0) == guess1.charAt(i)) {
    				match.replace(i, i+1, match1);
    			}
    		} return guess1=match.toString();
    
    	}
    	/**
    	*
    	* Method : main
    	*
    	*/
    	public static void main (String[] args) {
    		// Collect the random word
    		String guessword;
    		// Classified the letter of the word
    		int selection;
    
    		do {
    			guessword = JOptionPane.showInputDialog(null,"Please enter a word.");
    		} while (guessword.length()<=3);
    		String guessword1 = new String(guessword);
    		selection = JOptionPane.showConfirmDialog(null,"Do you want to run method 1 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCEL_OPTION);
    		if (selection==JOptionPane.YES_OPTION) {
    			guessword1 = removeDoubletons(guessword1);
    			System.out.println(guessword1) ;
    		}
    		String guessword2 = new String(guessword);
    		int selection2;
    		selection2 = JOptionPane.showConfirmDialog(null,"Do you want to run method 2 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCEL_OPTION);
    		if (selection2==JOptionPane.YES_OPTION) {
    			guessword2 = randomMove(guessword2);
    			System.out.println(guessword2) ;
    		}
    		String guessword3 = new String(guessword);
    		int selection3;
    		selection3 = JOptionPane.showConfirmDialog(null,"Do you want to run method 3 on the string you have just input?","Select an Option",JOptionPane.YES_NO_CANCEL_OPTION);
    		if (selection3==JOptionPane.YES_OPTION) {
    			guessword3 = removeVowels(guessword3);
    			System.out.println(guessword3) ;
    		}
    
    		String guesstwice = " ";
    		Boolean expression = true;
    
    		String unknown = codeWord(guessword);
    
    		while (expression) {
    			guesstwice = JOptionPane.showInputDialog(null, unknown=ReplaceDash(guesstwice .toLowerCase(), guessword.toLowerCase(), unknown) + "\nPlease enter a single chracter, or a word as your final guess.");
    			if (guesstwice.length()>1) {
    				expression = endGame(guesstwice, guessword1);
    			}
    		}
    
    	}// end of main method
    
    } // end of class StringGame
    
    
    
    thanks a lot mate
    Offline

    13
    ReputationRep:
    (Original post by ahieuheo74)
    I am having a file StringGame.java

    At school, my teacher guided me to open TERMINAL then type " javac StringGame.java " to create the StringGame.html file. However, after I edited the *.java file by changing some code. Then I am not be able to create the StringGame.html

    Anyone knows how to do it ?:confused:
    Try to compile the original file if you've got it. You're best bet is to find your solution on here:

    http://ubuntuforums.org/

    Most of the time, there are comprehensive HOW-TOs etc which should help you in greater detail. Sorry I couldn't give a better answer.
 
 
 
Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: December 8, 2010
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Did TEF Bronze Award affect your UCAS choices?
    Useful resources

    Articles:

    The Student Room tech wikiTech forum guidelines

    Quick link:

    Unanswered technology and computers threads

    Sponsored features:

    Web Legend

    Win a Macbook Air!

    Blog about setting up a website for a chance to win in our Web Legend competition.

    Groups associated with this forum:

    View associated groups
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.