Results 1 to 3 of 3
  1. #1
    smileybear33 is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default Need help with assignment.

    Well, once again I'm back and have an assignment due tonight and I am so lost. I am having a hard time figuring out how to really even get started with this code. Any help would be appreciated. The assignment reads:

    Evey seven-letter phone number corresponds to many seven-letter words, but most of these words represent unrecognizable juxstapositions of letters. It's possible, however, that the owner of a barbershop would be pleased to know that the shop's telephone number, 424-7288, corresponds to "HAIRCUT." A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters "PETCARE."

    Write a program that, given a seven digit (phone) number, uses a PrintStream object to write to a file every possible seven-letter word combination corresponding to that number. There are 2,187 (3^7) such combinations. Avoid phone numbers with the digits 0 and 1.


    Some of the code was provided for me and I've started it but don't even know if I'm on the right track or if I'm way off base. Printing and reading from a file confuses me so much. Here is the code:
    Java Code:
    import java.util.Formatter;
    
    /**
     * 
     * @author 
     * @version Spring 2011
     *
     */
    public class PhoneNumber {
    
    	/**
    	 * This method writes all possible character combinations represented by
    	 * 'phoneNumber' into the file 'filename'.  The user is then responsible
    	 * for looking through the file to determine if any of these combinations
    	 * are real words 
    	 * 
    	 * @param phoneNumber is the 7 digit phone number in question
    	 * @param filename indicates where to store this file.
    	 */
    	
    	/**
    	 * Wouldn't it be nice if you had a method that took an int and returned
    	 * the associated char[] ?
    	 */
    	
    	public static void writeToFile(int phoneNumber, String filename){
    		//This is the code that I added but I'm not sure what I'm doing here.
    		Formatter out = new Formatter("filename");
    		for (int i = 1; i < 7; i++){
    			System.out.print(i + " \n");
    			out.format(i+"\n");
    		}
    		
    		
    	}
    
    	/**
    	 * This function takes 7 arrays and prints all combinations of the characters to the screen
    	 * You may find this useful
    	 */
    	public static void writeHelper(String filename, char a1[], char a2[], char a3[], char a4[],char a5[],char a6[],char a7[]){
    		for (int i = 0; i < a1.length; i++){
    			for (int j = 0; j < a2.length; j++){
    				for (int k = 0; k < a3.length; k++){
    					for (int l = 0; l < a4.length; l++){
    						for (int m = 0; m < a5.length; m++){
    							for (int n = 0; n < a6.length; n++){
    								for (int o = 0; o < a7.length; o++){
    									System.out.println( "" + a1[i] + a2[j]+ a3[k]+ a4[l]+ a5[m]+ a6[n]+ a7[o]);
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    	
    	public static void main(String[] args) throws Exception {
    		
    		writeToFile(6862377, "Numbers.txt");
    		writeToFile(8253688, "Takeout.txt");
    
    	}
    
    }
    Any help anyone could give me I'd appreciate it. I've been looking at this assignment all weekend and haven't made heads or tails of it.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by smileybear33 View Post
    Some of the code was provided for me and I've started it but don't even know if I'm on the right track or if I'm way off base. Printing and reading from a file confuses me so much. Here is the code:
    There's no direct answerable question in your post, just that your confused with file handling and a code dump, so about the best that I can do is point you to the file output tutorial. Perhaps someone can give you better help, but if not, you might do well to tell us what is wrong with your program, what errors you are having, and what specifically confuses you.

    Edit: per your instructions: "uses a PrintStream object to write to a file",

    You should create a PrintStream object before your loops and write to this object. The PrintStream API will tell what method(s) to use to output text with this object (hint, System.out is a PrintStream object and you know how to output with this object as your code demonstrates).
    Last edited by Fubarable; 04-26-2011 at 03:22 AM.

  3. #3
    smileybear33 is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Thank you very much. I'll look through that webpage and see if it will help me at all. If it doesn't I'll see if I can come up with a more specific question to ask to help my question to be more clear.

Similar Threads

  1. assignment
    By mr.othman in forum New To Java
    Replies: 4
    Last Post: 12-03-2010, 03:55 PM
  2. I am looking for help with an assignment
    By nanoo51969 in forum New To Java
    Replies: 1
    Last Post: 03-23-2009, 10:41 PM
  3. GUI First Assignment-DUE 8/1/08
    By ljk8950 in forum AWT / Swing
    Replies: 2
    Last Post: 08-01-2008, 05:23 AM
  4. First GUI Assignment
    By ljk8950 in forum New To Java
    Replies: 1
    Last Post: 07-31-2008, 08:29 AM

Posting Permissions

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