Is there anyway to modify this? Or other way for writing it?

import java.util.Scanner;

import java.util.Random;

import java.io.*;

publicclass WordGuess{

publicstaticvoid main(String[] args){

final String FLAG ="!";

File wordsFile =new File("secret.txt");

FileReader in;

BufferedReader readFile;

Random r =new Random();

int numWords, wordToGuess;

String secretWord ="";

String wordSoFar ="", updatedWord ="";

String letterGuess, wordGuess ="";

int numGuesses = 0;

Scanner input =new Scanner(System.in);

try{

in =new FileReader(wordsFile);

readFile =new BufferedReader(in);

numWords = Integer.parseInt(readFile.readLine());

wordToGuess = r.nextInt(numWords) + 1;

for (int word = 1; word <= wordToGuess; word ++){

secretWord = readFile.readLine();

}

readFile.close();

in.close();

}catch (FileNotFoundException e){

System.out.println("File does not exist or could not be found.");

System.err.println("FileNotFoundException: " + e.getMessage());

}catch (IOException e){

System.out.println("Problem reading file.");

System.err.println("IOException: " + e.getMessage());

}

System.out.println("WordGuess game.\n");

for (int i = 0; i < secretWord.length(); i++){

wordSoFar +="-";

}

System.out.println(wordSoFar +"\n");

do{

System.out.print("Enter a letter (" + FLAG +" to guess entire word): ");

letterGuess = input.nextLine();

letterGuess = letterGuess.toUpperCase();

numGuesses += 1;

if (secretWord.indexOf(letterGuess) >= 0){

updatedWord = wordSoFar.substring(0, secretWord.indexOf(letterGuess));

updatedWord += letterGuess;

updatedWord += wordSoFar.substring(secretWord.indexOf(letterGuess)+1, wordSoFar.length());

wordSoFar = updatedWord;

}

System.out.println(wordSoFar +"\n");

}while (!letterGuess.equals(FLAG) && !wordSoFar.equals(secretWord));

if (letterGuess.equals(FLAG)){

System.out.print("What is your guess? ");

wordGuess = input.nextLine();

wordGuess = wordGuess.toUpperCase();

}

if (wordGuess.equals(secretWord) || wordSoFar.equals(secretWord)){

System.out.println("You won!");

}else{

System.out.println("Sorry. You lose.");

}

System.out.println("The secret word is " + secretWord);

System.out.println("You made " + numGuesses +" guesses.");

}

}

[4669 byte] By [wiwia] at [2007-11-27 5:13:04]
# 1
another one of these? hmmm...are you copying homework solutions from somewhere, and then coming here to ask people to disguise them?
OnBringera at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 2
Do u atleast know what the program does ?
New_Kida at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 3
noooo.. I DID NOT COPY!!! I did this program, but my teacher told me to modify it to get 30 bonus points which is a great deal. But i can't think of ways to modify it. = =Message was edited by: wiwi
wiwia at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 4
Can u explain the program then?
New_Kida at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 5

import java.util.Scanner;

import java.io.*;

/**

* Counts the number of vowels in a text file.

*/

public class CountVowels {

public static void main(String[] args) {

File textFile;

FileReader in;

BufferedReader readFile;

String fileName;

String lineInFile, lowercaseText, letter;

int vowelSum = 0;

Scanner input = new Scanner(System.in);

/* prompt the user for the name of the file */

System.out.print("Enter the file name: ");

fileName = input.nextLine();

/* count the vowels in the file */

try {

textFile = new File(fileName);

in = new FileReader(textFile);

readFile = new BufferedReader(in);

while ((lineInFile = readFile.readLine()) != null) {

lowercaseText = lineInFile.toLowerCase();

for (int i = 1; i <= lowercaseText.length(); i++) {

letter = lowercaseText.substring(i-1, i);

if (letter.equals("a") || (letter.equals("e")) || (letter.equals("i")) || (letter.equals("o")) || (letter.equals("u")) ) {

vowelSum += 1;

}

}

}

System.out.println("The number of vowels in " + fileName + " is " + vowelSum + ".");

readFile.close();

in.close();

} catch (FileNotFoundException e) {

System.out.println("File does not exist or could not be found.");

System.err.println("FileNotFoundException: " + e.getMessage());

} catch (IOException e) {

System.out.println("Problem reading file.");

System.err.println("IOException: " + e.getMessage());

}

}

}

wiwia at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 6

> noooo.. I DID NOT COPY!!!

don't shout at me

> I did this program, but my teacher told me to modify

> it to get 30 bonus points which is a great deal.

how many bonus points you getting for this one:

http://forum.java.sun.com/thread.jspa?threadID=5175586

> But

> i can't think of ways to modify it. = =

you wrote it, and you can't think of any way to write it differently? okay. "i believe you".

for starters, you could replace your use of hardcoded Linux newline character to use the system property line.separator.

OnBringera at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 7
does it have to be more specific?
wiwia at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 8

i didn't mean to shout at you.. it's just an exclamatory mark, alright?

i'm not an aggressive person ...

i really made the wrong choice of studying Java. I'm not good at it . As I have said, guys in my class rarely helped me. If i can do it, i wouldn't ask help from you guys =(

And maybe i'm also wrong for asking the forum to help me..

wiwia at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 9
Did u notice that the 2 programs u posted are different !!!
New_Kida at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 10

okay.. it's so embarrassing.. hahahahahaha+

sorry.. i was so blurred.. i was asking help for two of these programs..

import java.util.Scanner;

import java.util.Random;

import java.io.*;

/**

* Plays a word guess game using a randomly selected word from a file. The word file

* contains the number of words in the file in the first line and then words on separate

* lines below.

*/

public class WordGuess {

public static void main(String[] args) {

final String FLAG = "!";

File wordsFile = new File("words.txt");

FileReader in;

BufferedReader readFile;

Random r = new Random();

int numWords, wordToGuess;

String secretWord = "";

String wordSoFar = "", updatedWord = "";

String letterGuess, wordGuess = "";

int numGuesses = 0;

Scanner input = new Scanner(System.in);

/* select secret word */

try {

in = new FileReader(wordsFile);

readFile = new BufferedReader(in);

numWords = Integer.parseInt(readFile.readLine());

wordToGuess = r.nextInt(numWords) + 1;

for (int word = 1; word <= wordToGuess; word ++) {

secretWord = readFile.readLine();

}

readFile.close();

in.close();

} catch (FileNotFoundException e) {

System.out.println("File does not exist or could not be found.");

System.err.println("FileNotFoundException: " + e.getMessage());

} catch (IOException e) {

System.out.println("Problem reading file.");

System.err.println("IOException: " + e.getMessage());

}

/* begin game */

System.out.println("WordGuess game.\n");

for (int i = 0; i < secretWord.length(); i++) {

wordSoFar += "-";//word as dashes

}

System.out.println(wordSoFar + "\n");//display dashes

/* allow player to make guesses*/

do {

System.out.print("Enter a letter (" + FLAG + " to guess entire word): ");

letterGuess = input.nextLine();

letterGuess = letterGuess.toUpperCase();

/* increment number of guesses */

numGuesses += 1;

/* player correctly guessed a letter--extract string in wordSoFar up to the letter

* guessed and then append guessed letter to that string. Next, extract rest of

* wordSoFar and append after the guessed letter

*/

if (secretWord.indexOf(letterGuess) >= 0) {

updatedWord = wordSoFar.substring(0, secretWord.indexOf(letterGuess));

updatedWord += letterGuess;

updatedWord += wordSoFar.substring(secretWord.indexOf(letterGuess)+1, wordSoFar.length());

wordSoFar = updatedWord;

}

/* display guessed letter instead of dash */

System.out.println(wordSoFar + "\n");

} while (!letterGuess.equals(FLAG) && !wordSoFar.equals(secretWord));

/* finish game and display message and number of guesses */

if (letterGuess.equals(FLAG)) {

System.out.print("What is your guess? ");

wordGuess = input.nextLine();

wordGuess = wordGuess.toUpperCase();

}

if (wordGuess.equals(secretWord) || wordSoFar.equals(secretWord)) {

System.out.println("You won!");

} else {

System.out.println("Sorry. You lose.");

}

System.out.println("The secret word is " + secretWord);

System.out.println("You made " + numGuesses + " guesses.");

}

}

wiwia at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...
# 11

> i didn't mean to shout at you.. it's just an

> exclamatory mark, alright?

that's not what i mean. all caps is shouting. LIKE I'M SHOUTING AT YOU RIGHT HERE. this for your info.

> i'm not an aggressive person ...

i am

> i really made the wrong choice of studying Java. I'm

> not good at it . As I have said, guys in my class

> rarely helped me.

you're not playing your cards right then

OnBringera at 2007-7-12 10:34:28 > top of Java-index,Java Essentials,New To Java...