Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need help with array list, scanner and dictonary file.

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with array list, scanner and dictonary file.

    I need some help with a programming assignment. I haven't looked at Java in over 9 years. My son is a comp sci major and is having trouble with this assignment and asked for my help. Yes I know big mistake, but that is where I'm at. We have to create a program that involves word chains. Those are 4 letter words that are 1 letter off of the original word. Ie tick, pick, sick, etc... we have the array created.

     
    import java.util.*;
    public class ArrayListOne {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		 // create an array list
    	      ArrayList<String> al = new ArrayList<String>();
     
    	}
     
    }

    And we have the scanner code..

     
    import java.util.Scanner;
    public class scanner {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner scan = new Scanner(System.in);
    		System.out.println("Input starting word: ");
    		String start = scan.nextLine();
    		//somewhere here you would add it to the Array list.
    		System.out.println("Input final word: ");
    		String last = scan.nextLine();
    		//somewhere here you would add it to the Array list.
     
     
    	}
     
    }

    So my question is how is the best way to add this to the array so we can then construct a while loop to scan the dictionary file ( which is a text file ) with hundreds of 4 letter words. Please point us in the right starting direction and be kind as I said I haven't looked at Java in over 9 years. Thanks in advanced


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need help with array list, scanner and dictonary file.

    You said it: helping him like this is a pretty bad idea. Why don't you have him make a post instead?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help with array list, scanner and dictonary file.

    . . . a program that involves word chains . . .
    When he posts, have him describe the assignment better and his intended design for the program. What are the program's requirements, what does it do, why scan the dictionary of words, why are words added to the ArrayList, etc?

  4. #4
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with array list, scanner and dictonary file.

    I will have him post, but I can answer some questions. Plus this is an opportunity for me to learn as well. The user is to input a start word and a last word. These are then added to an arraylist. The dictionary file is then scanned and the program will pick out a 9 word chain where the 4 letter words are 1 letter different. Thanks again. I will send this page to him and have him fill some details.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need help with array list, scanner and dictonary file.

    More to the point: programming is at least 50% taking a step back, away from the computer, and breaking the problem down into smaller steps, then taking on each of those steps by using google, reading the documentation and tutorials.

    That's something your son should be doing mostly on his own, as it's the whole point of the programming assignment. The homework isn't (just) trying to teach him syntax, it's trying to teach him *the process* of working through a problem. You should try to be as hands-off as possible.

    I'm not trying to be rude, but the code you have is pretty barebones. You (and by you, I mean your son) need to take a step away from the computer and really think about what you're trying to do. Break the problem down into smaller pieces, and then break those pieces down into even smaller pieces. Pretend you have to do this without a computer, just with a real-life dictionary and a piece of paper and a pencil. How would you accomplish this then?

    Pretend you have a friend who has no idea how to accomplish your goal (again, not on a computer, but in real life). Write down instructions that your friend could follow to accomplish it anyway- remember, your friend has no idea how to do it, so your instructions have to be as specific as possible.

    When you have those instructions written out (in English, not in code), that will be an algorithm that you can start thinking about implementing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. The Following User Says Thank You to KevinWorkman For This Useful Post:

    GregBrannon (October 7th, 2014)

  7. #6
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with array list, scanner and dictonary file.

    I agree with everything you have said. I'm a VB.net developer so Java is lost on me.

Similar Threads

  1. Might be a thread leak problem reading a file into an Array list.
    By rushtonjj in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 10th, 2012, 06:56 AM
  2. Replies: 2
    Last Post: February 21st, 2012, 01:25 AM
  3. Replies: 3
    Last Post: December 2nd, 2011, 11:53 AM
  4. Reading file of floats into array list and sorting into subsets
    By Skave in forum Collections and Generics
    Replies: 2
    Last Post: November 9th, 2011, 07:03 PM
  5. loading things from a text file into an array list
    By sp11k3t3ht3rd in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 6th, 2011, 03:32 PM