Urgent Help

Talk about and discuss various advancements and achievents in the arts and sciences of invention and modification; computers, sciences, mathematics, and technology for all.
Post Reply
User avatar
Deepak
Posts: 2789
Joined: Fri Nov 19, 2004 3:02 am
Contact:

Urgent Help

#1

Post by Deepak »

So im doing compsci 101 and I really need help. I have had assignment and tests like all over the place and I'm like really brain dead with this assignment. the assginmentin pdf is : http://www.cs.auckland.ac.nz/compsci101 ... /A2/A2.pdf

the skeleton files :

WordChainingApp.java

/**
* This program creates and instance
* of the WordChaining class.
*
* @author Adriana Ferraro
* @version 2006
*/
public class WordChainingApp {
public static void main(String[] args) {
WordChaining program = new WordChaining();
program.start();
}
}



WordChaining.java

/**
Add comment here.
*/
public class WordChaining {

//--------------------------------------------------------------------------
//------------------ ORGANISE GAME UNTIL PLAYER WISHES TO QUIT -------------
//--------------------------------------------------------------------------
public void start() {






}




//--------------------------------------------------------------------------
//------------------ OBTAIN A RANDOM WORD ----------------------------------
//--------------------------------------------------------------------------
private String getRandomWord( ) {
String theWord = Words.getRandomWord();
return theWord.toUpperCase();
}
}


Keyboard.java

/*
CompSci 101 - Keyboard Class
============================
This class is used for input from the keyboard.
YOU DO NOT NEED TO UNDERSTAND THE DETAILS OF THIS CLASS.
To use this class, put it in the same directory as the source
file for your program, and include the statement:
String input = Keyboard.readInput();
in your program. This will assign whatever is typed at the
keyboard to the input variable.
*/
import java.io.*;
public class Keyboard {
private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static String readInput() {
try {
return in.readLine();
}
catch (IOException e) {
System.out.println("An error has occurred in the Keyboard.readInput() method");
System.out.println(e.toString());
System.exit(-1);
}
return null;
}
}



Words.java

/**
* This class represents a list
* of 6 letter words. The class
* produces random words from the
* list of words.
*
* @author Adriana Ferraro
* @version 2006
*/

public class Words {
//--------------------------------------------------------------------------
//------------------------- CONSTRUCTOR ------------------------------------
//--------------------------------------------------------------------------
/**
* The constructor is private
*
* @parameter NA
*/
private Words(){

}
//--------------------------------------------------------------------------
//------------------ PUBLIC METHOD TO OBTAIN A RANDOM WORD -----------------
//--------------------------------------------------------------------------
/**
* This method obtains a new random word from
* the words in the String, allWords.
*
* @parameter N/A
* @return The random word
*/
public static String getRandomWord() {
String theWord = "";
int i = 0;
String words2 = getPossibleWords();
String words = getPossibleWords();
int numberOfWords = getNumberOfWords( words );
int randNumber = (int) ( Math.random() * numberOfWords + 1 );
int posOfNextSpace = words.indexOf( ", " );

while( i < randNumber && posOfNextSpace > -1 ) {
theWord = words.substring( 0, posOfNextSpace );
words = words.substring( posOfNextSpace+2 );
theWord = theWord.trim();
posOfNextSpace = words.indexOf( ", " );
i++;
}

if ( posOfNextSpace == -1 )
return words.trim();

return ( words.substring( 0, posOfNextSpace ) ).trim();
}
//--------------------------------------------------------------------------
//------------------ PRIVATE METHODS USED TO CREATE THE --------------------
//------------------ LIST OF WORDS AND GET THE NUMBER ----------------------
//------------------ OF WORDS IN THE LIST ----------------------------------
//--------------------------------------------------------------------------
/**
* This method returns the number of words
* in the words string. The words are separated
* by blank spaces.
*
* @parameter The string of words
* @return The number of words
*/
private static int getNumberOfWords( String words ) {
int numberOfWords = 0;
int posOfNextSpace;

if (words.length() <= 2)
return 0;

posOfNextSpace = words.indexOf(", ");

while( posOfNextSpace > -1 ){
numberOfWords++;
words = words.substring( posOfNextSpace+2 );
words = words.trim();
posOfNextSpace = words.indexOf( ", " );
}
return numberOfWords+1;
}
/**
* This method returns the string of all the words
* listed in the method.
*
* @parameter N/A
* @return The string of words
*/
private static String getPossibleWords() {
String possibleWords = "ABLE, ABOUT, ABOVE, ACT, ADD, ADDED, AFTER, AGAIN, AGE, AGO, AHEAD, AID, AIR, ALIVE, ALL, ALLOW, ALONE, ALONG, ALSO, AMONG, AND, ANODE, ANY, APART, APPLY, APRIL, ARE, AREA, AREAS, ARM, ARMED, ARMS, ARMY, ART, ARTS, ASIDE, ASK, ASKED, AVOID, AWARE, AWAY, BABY, BACK, BAD, BALL, BANK, BAR, BASE, BASED, BASIC, BASIS, BAY, BEACH, BEAR, BEAT, BED, BEEN, BEGAN, BEGIN, BEING, BELOW, BEST, BIBLE, BIG, BILL, BIRDS, BIRTH, BIT, BLACK, BLOCK, BLOOD, BLUE, BOARD, BOAT, BODY, BOOK, BOOKS, BORN, BOTH, BOX, BOY, BOYS, BREAK, BRIEF, BRING, BROAD, BROKE, BROWN, BUILD, BUILT, BUSY, BUT, BUY, CALL, CALLS, CAME, CAMP, CAN, CAR, CARE, CARRY, CARS, CASE, CASES, CAUSE, CELL, CELLS, CENT, CHAIR, CHECK, CHIEF, CHILD, CHINA, CITY, CIVIL, CLAIM, CLASS, CLAY, CLEAN, CLEAR, CLOSE, CLUB, COAST, COLD, COLOR, COME, COMES, CONGO, COOL, CORPS, COST, COSTS, COULD, COURT, COVER, CROSS, CUT, DAILY, DANCE, DARK, DATA, DATE, DAY, DAYS, DEAD, DEAL, DEATH, DEEP, DESK, DID, DIE, DIED, DOES, DOG, DOGS, DOING, DONE, DOOR, DOUBT, DOWN, DRAW, DRAWN, DREAM, DRESS, DREW, DRINK, DRIVE, DROP, DROVE, DRY, DUE, DUST, DUTY, EACH, EARLY, EARTH, EAST, EASY, EAT, EDGE, EIGHT, ELSE, EMPTY, END, ENDED, ENDS, ENEMY, ENTER, EQUAL, ETC, EVEN, EVENT, EVER, EVERY, EVIL, EXIST, EYE, EYES, FACE, FACES, FACT, FACTS, FAIR, FAITH, FALL, FAR, FARM, FAST, FAT, FAVOR, FEAR, FEED, FEEL, FEET, FELL, FELT, FEW, FIELD, FIFTY, FIG, FIGHT, FILE, FILM, FINAL, FIND, FINDS, FINE, FIRE, FIRM, FIRMS, FIRST, FIT, FIVE, FIXED, FLAT, FLOOR, FLOW, FOOD, FOOT, FOR, FORCE, FORM, FORMS, FORT, FORTH, FOUND, FOUR, FRAME, FRANK, FREE, FRESH, FROM, FRONT, FULL, FULLY, FUND, FUNDS, GAIN, GAME, GAMES, GAS, GAVE, GET, GETS, GIRL, GIRLS, GIVE, GIVEN, GIVES, GLASS, GOAL, GOD, GOES, GOING, GONE, GOOD, GOODS, GOT, GRAY, GREAT, GREEK, GREEN, GREW, GROSS, GROUP, GROW, GUESS, GUN, HAD, HAIR, HALF, HALL, HAND, HANDS, HAPPY, HARD, HAS, HAT, HAVE, HEAD, HEAR, HEARD, HEART, HEAT, HEAVY, HELD, HELL, HELP, HENCE, HENRY, HER, HERE, HIGH, HILL, HIM, HIS, HIT, HOLD, HOLE, HOME, HOMES, HONOR, HOPE, HORSE, HOT, HOTEL, HOUR, HOURS, HOUSE, HOW, HUMAN, HUNG, IDEA, IDEAL, IDEAS, IMAGE, INCH, INDEX, INDIA, INTO, ISSUE, ITEMS, ITS, JACK, JAMES, JAZZ, JESUS, JOB, JOBS, JOE, JOHN, JOIN, JONES, JUDGE, JULY, JUNE, JURY, JUST, KEEP, KEPT, KEY, KID, KILL, KIND, KING, KNEW, KNIFE, KNOW, KNOWN, KNOWS, LABOR, LACK, LADY, LAID, LAND, LAOS, LARGE, LAST, LATE, LATER, LAW, LAWS, LAY, LEAD, LEARN, LEAST, LEAVE, LED, LEFT, LEG, LEGAL, LEGS, LESS, LET, LEVEL, LEWIS, LIE, LIFE, LIGHT, LIKE, LIKED, LINE, LINES, LIPS, LIST, LIVE, LIVED, LIVES, LOCAL, LONG, LOOK, LOOKS, LORD, LOSE, LOSS, LOST, LOT, LOUIS, LOVE, LOVED, LOW, LOWER, MADE, MAIN, MAJOR, MAKE, MAKES, MAN, MANY, MARCH, MARK, MARY, MASS, MAY, MAYBE, MEAN, MEANS, MEANT, MEET, MEN, MET, METAL, MIGHT, MIKE, MILE, MILES, MIND, MINDS, MINE, MINOR, MISS, MODEL, MONEY, MONTH, MOON, MORAL, MORE, MOST, MOTOR, MOUTH, MOVE, MOVED, MRS, MUCH, MUSIC, MUST, NAME, NAMED, NAMES, NEAR, NECK, NEED, NEEDS, NEGRO, NEVER, NEW, NEWS, NEXT, NICE, NIGHT, NINE, NONE, NOR, NORTH, NOSE, NOT, NOTE, NOTED, NOTES, NOVEL, NOW, OFF, OFFER, OFTEN, OIL, OLD, OLDER, ONCE, ONE, ONES, ONLY, ONTO, OPEN, ORDER, OTHER, OUGHT, OUR, OUT, OVER, OWN, PAGE, PAID, PAIN, PALE, PAPER, PARIS, PARK, PART, PARTS, PARTY, PASS, PAST, PAY, PEACE, PER, PHASE, PHIL, PICK, PIECE, PLACE, PLAN, PLANE, PLANS, PLANT, PLAY, PLAYS, PLUS, POEMS, POET, POINT, POOL, POOR, POST, POWER, PRESS, PRICE, PURE, PUT, QUICK, QUIET, QUITE, RACE, RADIO, RAIN, RAN, RANGE, RATE, RATES, REACH, READ, READY, REAL, RED, REST, RHODE, RICH, RIFLE, RIGHT, RISE, RIVER, ROAD, ROADS, ROCK, ROLE, ROMAN, ROME, ROOF, ROOM, ROOMS, ROSE, ROUND, RULE, RULES, RUN, RUNS, SAFE, SAID, SALES, SAM, SAME, SAN, SAT, SAVE, SAW, SAY, SAYS, SCALE, SCENE, SCORE, SEA, SEE, SEEK, SEEM, SEEMS, SEEN, SEND, SENSE, SENT, SERVE, SET, SETS, SEVEN, SEX, SHALL, SHAPE, SHARE, SHARP, SHE, SHIP, SHOOK, SHOP, SHORE, SHORT, SHOT, SHOW, SHOWN, SHOWS, SIDE, SIDES, SIGHT, SIGN, SIGNS, SINCE, SIR, SIT, SITE, SIX, SIZE, SKY, SLEEP, SLOW, SMALL, SMILE, SNOW, SOFT, SOLID, SOME, SON, SONG, SONGS, SOON, SORT, SOUND, SOUTH, SPACE, SPEAK, SPEED, SPENT, SPITE, SPOKE, SPOT, STAFF, STAGE, STAND, START, STATE, STAY, STEP, STEPS, STILL, STOCK, STONE, STOOD, STOP, STORE, STORY, STUDY, STYLE, SUCH, SUN, SURE, SWEET, TABLE, TAKE, TAKEN, TAKES, TALK, TASK, TASTE, TAX, TEAM, TEETH, TELL, TEN, TERM, TERMS, TEST, TESTS, TEXAS, TEXT, THAN, THAT, THE, THEIR, THEM, THEME, THEN, THERE, THESE, THEY, THICK, THIN, THING, THINK, THIRD, THIS, THOSE, THREE, THUS, TIME, TIMES, TITLE, TODAY, TOLD, TOM, TONE, TOO, TOOK, TOP, TOTAL, TOUCH, TOWN, TRADE, TRAIN, TREE, TREES, TRIAL, TRIED, TRIP, TRUCK, TRULY, TRUTH, TRY, TURN, TWICE, TWO, TYPE, TYPES, UNCLE, UNDER, UNION, UNIT, UNITS, UNITY, UNTIL, UPON, UPPER, USE, USED, USES, USING, USUAL, VALUE, VAST, VERY, VIEW, VISIT, VITAL, VOICE, VOTE, WAGE, WAIT, WALK, WALL, WALLS, WANT, WANTS, WAR, WARM, WAS, WATCH, WATER, WAY, WAYS, WEEK, WEEKS, WELL, WENT, WERE, WEST, WHAT, WHEEL, WHEN, WHERE, WHICH, WHILE, WHITE, WHO, WHOLE, WHOM, WHOSE, WHY, WIDE, WIFE, WILD, WILL, WIN, WIND, WINE, WISH, WITH, WOMAN, WOMEN, WON, WORD, WORD, WORDS, WORE, WORK, WORKS, WORLD, WORRY, WORTH, WOULD, WRITE, WRONG, WROTE, YARDS, YEAR, YEARS, YES, YET, YORK, YOU, YOUNG, YOUR, YOUTH, ";
return possibleWords.toUpperCase();
}
}
WHEN THE RICH WAGE WAR ITS THE POOR WHO DIE

BBcode:
Hide post links
Show post links
User avatar
Deepak
Posts: 2789
Joined: Fri Nov 19, 2004 3:02 am
Contact:

#2

Post by Deepak »

So its not that I want someone to write the whole code for me. I just need help in where tostart and how to do things. I did like a plan thingy but I just got this huge brain freeze and I only have one day to get this done. As it seems I will have to pull an all nighter again. Have been pulling those like every 2nd day all last week and even on monday.

I just need stuff to be layed out in lay mans terms and I should be ok. But

HELP!!!!


edit:: You only need to make changes to the WordChaining.java file.
WHEN THE RICH WAGE WAR ITS THE POOR WHO DIE

BBcode:
Hide post links
Show post links
Krystal
Posts: 12
Joined: Sun Mar 19, 2006 11:55 am

#3

Post by Krystal »

This is probably obvious, but I'd start on page 3 and one step at a time implement what assignment asks for.

Here's a page on Java IO that will help with reading user input and printing out to console:
http://www.cs.wisc.edu/~cs302/io/JavaIO.html

Also, google is always your friend. If assignment asks for something you don't know, just type the phrase into google searchbox and append "java" at the end.

Good luck.

BBcode:
Hide post links
Show post links
User avatar
Deepak
Posts: 2789
Joined: Fri Nov 19, 2004 3:02 am
Contact:

#4

Post by Deepak »

Thanks lol. Sorry to be a pain I know the basics lolz.

I have narrowed down things to much easier way to do it.

1. display random word.
2. promt user to enter word.
3. assign word to string name.
4. check to see that the word entered is the same length as the random word.
5. check to see that the random word and the word are not the same.
6.check to see only one character differs.
7. Print random word plus the new word
8. prompt enter to new word
9. go back to step 3 or
10. prompt user to start a new chain or quit.


The steps that im having trouble with are 5 and 7 and then doing the loop properly.

Its just that i know the syntax and everything its just that I cant string everything together right now to actually get it all running.

Im still on the planning stage and I write the code on paper 1st before going on the computer or maybe just the basic syntax and style to use in the programming but yeah.
WHEN THE RICH WAGE WAR ITS THE POOR WHO DIE

BBcode:
Hide post links
Show post links
Krystal
Posts: 12
Joined: Sun Mar 19, 2006 11:55 am

#5

Post by Krystal »

5. Check out this String class spec: http://java.sun.com/j2se/1.4.2/docs/api ... tring.html
I'd go with equalsIgnoreCase method

7. I'd store the wordchain in a String variable. Whenever user enters a good word, append it to the end of the wordchain right after the last word supplied by the computer. Then print out the updated value of the wordchain var.

I find that I get things done faster in front of the computer because I can immediately verify my assumptions. Otherwise, if you base your program on even one false assumption, your whole plan might come down like a house of cards.

BBcode:
Hide post links
Show post links
User avatar
Deepak
Posts: 2789
Joined: Fri Nov 19, 2004 3:02 am
Contact:

#6

Post by Deepak »

Thanks again. I knew I had to do that but the question was how to do it. Figured that out last night but a few new problems have come forth with the checking of words and then going back into the loop and stuff. I'll figure it out though. Thanx again.
WHEN THE RICH WAGE WAR ITS THE POOR WHO DIE

BBcode:
Hide post links
Show post links
User avatar
Deepak
Posts: 2789
Joined: Fri Nov 19, 2004 3:02 am
Contact:

#7

Post by Deepak »

/**
Add comment here.
*/
public class WordChaining {

//--------------------------------------------------------------------------
//------------------ ORGANISE GAME UNTIL PLAYER WISHES TO QUIT -------------
//--------------------------------------------------------------------------
public void start() {

intialise ();





}

private void intialise (){
String generatedWord = getRandomWord();

System.out.println ("Each new word in the chain can have only one letter different from the previous word in the chain");
System.out.println ("n The current word chain: " + generatedWord);
getUserInput("",generatedWord);

}

private void getUserInput(String chain, String generatedWord){
chain= chain +" "+ generatedWord;
String userInput;
System.out.println("Enter next word");
System.out.print("(press Enter to stop chain): ");
userInput = Keyboard.readInput();


userInput = userInput.toUpperCase().trim();
compareLength(generatedWord.length(), userInput.length(), generatedWord, userInput, chain);

}


private void compareLength(int a, int b, String generatedWord, String userInput, String chain){
if (a==/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" />{
compareChars(generatedWord, userInput, chain);

}else{
notValid(generatedWord, userInput, chain);
}

}


private void compareChars(String a, String b, String chain){
int counter=0;
for (int i =0; i<a.length();i++){
if (a.charAt(i) != b.charAt(i)){
counter++;
System.out.println(counter);
}
}
if (counter >1 || counter == 0){
notValid(a,b,chain);
}else if (counter == 1){
// if (chain.length() > a.length()+1 &&chain.indexOf(/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" />!=-1){
// notValid(a,b,chain);
// }else{
currentWordChain(chain,a,/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" />;
// }
}

}

private void notValid(String generatedWord, String word, String chain){
System.out.println(word +" is not valid");



getUserInput(chain, word);
}

private void currentWordChain (String chain, String generatedWord, String userInput){

System.out.println("The current word chain: " +chain +" "+userInput);
getUserInput(chain,userInput);
}


// not actually made a call to this method
private String exit (String chain, String userInput){
int inputLength = userInput.trim().length();
int chainLength = chain.trim().length();
int stepsTaken = chainLength/inputLength;
String trim = chain.trim();
String generatedWord = trim.substring(0,inputLength);
return ("From "+ generatedWord + " to " + userInput + " in " + stepsTaken + " steps");
}

//--------------------------------------------------------------------------
//------------------ OBTAIN A RANDOM WORD ----------------------------------
//--------------------------------------------------------------------------
private String getRandomWord( ) {
String theWord = Words.getRandomWord();
return theWord.toUpperCase();
}
}
WHEN THE RICH WAGE WAR ITS THE POOR WHO DIE

BBcode:
Hide post links
Show post links
Post Reply