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 5 of 5

Thread: Storing Multiple Phone Numbers into Single Array

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Storing Multiple Phone Numbers into Single Array

    Hey guys, I'm working on a program and I'm stuck. This particular program is supposed to prompt the user to input either an uppercase or lowercase Y to process a phone number, they are then prompted to enter the character representation of a phone number (like CALL HOME would be 225-5466), this repeats until the user enters something other than the letter Y. All of the words entered are to be stored into a single array. The program is then to convert these words in the array to actual phone numbers. I'm kind of confused as to how to set this up. Here is what I have so far.

     import java.util.*;
    		public class Program1 {
     
    		public static void main(String[] args) {
    			Scanner input = new Scanner(System.in);
    				String begin;
    				int phoneNumber = number.convertNum(); 
    				System.out.println("Please enter an uppercase or lowercase Y when you are ready to enter a telephone number: ");
    					begin = input.next();
    					while (begin.equals("y") || begin.equals("Y")) {
    				System.out.println("Please enter a telephone number expressed in letters: ");
    				  String letters = input.next();
    				  char[] phoneArray = letters.toCharArray();
    				System.out.println("Please enter an uppercase or lowercase Y when you are ready to enter a telephone number: ");
    				begin = input.next();
    					}
    				System.out.println("Here is the numeric representation of the phone number(s) you entered");
    		}
     
    		public static int convertNum(char[] phoneArray) { 
     
     
    			return number;
    		}
    	}

    I realize that the second method doesn't have anything to return yet, I just wanted to put that in there while I was doing things that I actually know how to do ha. The convertNum() method is supposed to be the method with which the array of characters is converted to phone numbers.

    I'm still trying to think my way through this. I would think it'd be easier to store the inputs from the user as individual letters rather than words for the sake of converting to phone numbers.

    Also, we are only supposed to recognize the first 7 letters of each word that is entered, like the CALL HOME example, there are 8 letters but it's still a seven digit phone number, so I'm not sure how that would work.

    Also, when printing the phone numbers after they've been converted, we're supposed to print the hyphen after the third number, I have no clue how that would be done from an array.

    I was actually feeling pretty good about this program until I reached this point ha. Any help would be greatly appreciated.


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

    Default Re: Storing Multiple Phone Numbers into Single Array

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    You've done a pretty good job of thinking through the program and recognizing the parts to be done, but now you've been overwhelmed by the parts you lack the confidence to program. We've all been there.

    Write down the steps you've come up with - I put them as comments in my source code - and then take a deep breath and write the code to do each step. Complete the code for each step, one step at a time, test it, and when you think you've gotten it working, move to the next step.

    If you're unsure how to declare, initialize, and add elements to an array, check your textbook, class notes, or the Oracle tutorials for pointers.

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

    Default Re: Storing Multiple Phone Numbers into Single Array

    Thanks for the tips! That's basically what I've been doing, only on a separate sheet of paper rather than as comments in the code itself. But you're definitely right, I'm overwhelmed for sure, I haven't worked with Java in about a year and have had to learn Visual Basic since doing anything with Java so I'm having to try and not mix them up. That being said, I've never written a program anything like this before. Every program I've done in the past has been basically take input from a user or a file, store it in an array, and print the array, never anything like get input, store it to an array in a way that you will be able to literally convert the letters into numbers and repeat that numerous times, and print the array without it just being one long stream of numbers. My professor is super tough and this program (even though it's pretty basic) is actually more advanced than what the book covers. I've tried googling, but don't really know how to word what it is I"m searching for (I've tried searching things such as "converting letters stored in an arry into numbers", but that just gives me a bunch of tutorials on how to convert a string array into an int or double array). Sorry for rambling, I"m just tired and it doesn't look like I'll be going to bed any time soon seeing as there are several other parts to this assignment that I can't complete until the program is actually written and working properly. Thanks for the help though.

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

    Default Re: Storing Multiple Phone Numbers into Single Array

    Since the conversion is based on a phone number pad - a crypto key of sorts, you'll have to write your own conversion. Yes, it's been done a million times, because this is a common programming assignment, so there are likely solutions posted on the 'net, but it's not too hard, and you should work through it yourself. Consider using a switch statement or a number of if statements. Pretty straightforward really.

  5. #5
    Junior Member
    Join Date
    Jul 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Storing Multiple Phone Numbers into Single Array

    I have my if statements for the conversion written out, just having trouble actually getting to that point.

Similar Threads

  1. Replies: 1
    Last Post: May 8th, 2014, 06:40 AM
  2. Trying to find 3 largest numbers in an array using a single For loop
    By javaD1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 7th, 2014, 10:27 AM
  3. Storing unique random numbers
    By ajw1993 in forum Java Theory & Questions
    Replies: 3
    Last Post: April 10th, 2013, 09:03 AM
  4. Storing random numbers into a String field
    By ajw1993 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 23rd, 2013, 10:44 AM
  5. help w/ storing/scanning numbers in arrays
    By robertsbd in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 17th, 2010, 10:55 PM

Tags for this Thread