Converting Letters To A Phone Number?
Oct 19, 2014
I had to write a program for class using the method definition "public static char getNumber(char upperCaseLetter)" It compiles and runs but wont print out my final answer.
import java.util.Scanner;
public class Phone_0104730303 {
public static char getNumber(char upperCaseLetter)
{
char return_val = 0;
[Code].....
View Replies
ADVERTISEMENT
May 2, 2015
I am trying to validate the phone number with a method called isValidAddress and whenever it gets to that line of code in the while loop I get a lot of red line java exceptions. I am referring to lines 130-138
package pa4;
import ch9.Contact;
import ch9.SortPhoneList;
import pa4.pa4Delegate;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import java.awt.event.ActionEvent;
[Code] ....
View Replies
View Related
Sep 29, 2011
I'm trying to write a method that returns a number, given an uppercase letter as follows:
public static int getNumber(char uppercaseLetter)
The program is supposed to prompt the user to enter a phone number as a string. The input number may contain letters. The program translates a letter (upper- or lowercase) to a digit and leaves all other characters intact.
My code is below:
import java.util.*;
public class PhoneKeypad {
public static void main(String[] args){
System.out.print("Enter a string: ");
Scanner input = new Scanner(System.in);
String phNumber = input.next();
[Code] ....
I am getting these errors:
java.lang.ClassFormatError: Duplicate field name&signature in class file Chapter9/PhoneKeypad
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[Code] ...
View Replies
View Related
May 13, 2011
I am trying to make a phone number generator. I get the following error though when trying to compile.
my post
C:JAVA_PROGRAMMING_CODEcode1RandomPhoneNum>javac RandomPhoneNum.java
RandomPhoneNum.java:23: cannot find symbol
symbol : method toOctalString(int)
location: class RandomPhoneNum
strippedNum = toOctalString(num1);
^
1 error
Here is the code so far
import java.util.Random;
public class RandomPhoneNum
{
public static void main(String[] args)
{
System.out.println("This app prints out a random phone number.");
[Code] ....
Also, how did you people know about octal base numbers? I would never have known that. What I can do to improve my math ability?
View Replies
View Related
Apr 30, 2013
I am new to java, and now i have an assignment. I have to parse a phone number like this--> (656) 345 6544 to 6563456544. I've writen the following code that works great with a while loop. Now i would like to know how can i make it work with a for loop.
and the code is
import java.io.*;
public class Tema
{
public static String removeChar(String str, int i) {
String first= str.substring(0,i);
[Code] .....
View Replies
View Related
Apr 5, 2014
import java.util.*;
public class PhoneNumber {
private int areacode;
private int number;
private int ext;
PhoneNumber() {
[Code] .....
I just can't seem to get it completely correct.
PhoneNumber.java:35: error: incompatible types: int cannot be converted to String
areacode = Integer.parseInt(str[0]);
^
PhoneNumber.java:38: error: cannot find symbol
for(i = 0; i < number.length; i++){
^
symbol: variable length
[Code] ......
View Replies
View Related
Jul 25, 2014
I got a phone number problem. I get a list of phone numbers and a word file containing words, how could I need to see if I could match the phone number to 7 letter words, then see if I can match the first 3 numbers to 3 letter words and then the last 4 numbers to 4 number words. I figured all that out so far. The last part of this assignment is to see if I could match a combination of words together to match the phone numbers.
Example:
531 3259
IGETMILK
View Replies
View Related
Feb 17, 2014
I'm trying to output a ten digit phone number as a string on one file, and write another program to write it as a long because I don't know what value I need to use in order to get the code to run properly on either one.
View Replies
View Related
Mar 12, 2014
Instruction: You work for a telemarketing company and you are required to write a JAVA program that will generate a random phone number. (talk about a real-world application)
-The phone number should consist of 10 digits
-The first 3 are the area code and should not begin with 0, 8 or 9
-The second 3 digits should not be greater than 742 and not less than 100.
-The last 4 digits can be any digits
-Print the number using the following format: "(xxx)-xxx-xxxx", this way it will look like a real phone number (use decimal formatting)
by this : Generating Random Numbers
Using arithmetic operations
View Replies
View Related
Apr 11, 2011
I've been working on a personal project again in Unit 3 of my text book and this time they want me to make a random phone number generator. Here's the actual directions:
"Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX.
Include the dashes in the output.
Do not let the first three digits contain an 8 or 9 (but don't be more restrictive than that), and make sure that the second set of three digits is not greater than 742.
Think through the easiest way to construct the phone number. Each digit does not have to be determined separately."
With this assignment I came across 2 problems:
1. What I tried was that since the first 3 numbers have to be a random number with no 8's or 9's I tried doing this algorithm:
int first0, first1, first2, second, third, random0;
first0 = generator.nextInt (999);
random0 = generator.nextInt (8);
first1 = first0.replace('8', random0);
first2 = first1.replace('9' random0);
The problem is that Java won't allow me to generate random numbers this way. Are there any easier ways of generating numbers that doesn't contain specific number (such as 8 or 9 in this case?)
2. I was thinking about this throughout the whole project and what if I generate a number such as 27 (less than 3 or 4 digit number) rather than 3 or 4 digit numbers? How would it show 0027 or 027 instead of 27 for the phone numbers?
import java.util.Random;
public class pp0303 {
public static void main (String[] args){
Random generator = new Random();
int first0, first1, first2, second, third, random0;
[Code] ....
RESULTS:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot invoke replace(char, int) on the primitive type int
Cannot invoke replace(char) on the primitive type int
Syntax error on token "random0", delete this token
at pp0303.main(pp0303.java:15)
View Replies
View Related
Nov 30, 2014
Applications: Netbeans (8.0.1), Apache Tomcat
My Aim: Creation of a telephone book
How should it work:
I have a Database with Data of people (name, adress, phone number).
If a user enters a phone number (CLIENT) -> the correct person with the name and adress should appear.
I build up the infrastructure and now I'm at the point that I have to create a Webmethod for it. I just worked on projects like addition of two integers, hello "name", ... I think this example now is harder, BUT i can learn a lot!
View Replies
View Related
Dec 3, 2014
What my program needs to do:
1) accepts a filename from the user that indicates the input file
2)obtains a filename to use as the output file
3)the program then reads the file and reports how many of each letter are there in the file.
4)if the file could not be opened, you must ask the user for valid file name until one is given
5)once a valid file name is given, print all of contents and store the analysis of the file in the output file name specified
You will be reading the input from a file and printing the output to another file. For example, if the file input.txt contains:
This file contains lett3rs.
YoU counT Only lEtTers, not numb3rs.
How many h's are in "Ohhhhhhhhhhh no!"?
The program should ignore white spaces, new lines and other special characters or numbers. It should count only the letters (a-z and/or A-Z) in the input file.
An example execution might look like this:
Input a file name: notAFile.txt
Invalid filename given. Input another.
Input a file name: alsoNotAFile.txt
Invalid filename given. Input another.
Input a file name: input.txt
[Code] ....
1)The last try/catch block was given by my professor, however the only thing it does is print out "hello java" into an out file. How would I make it print out similar to that of the given example?
2)I figured out how to make the array print out ABCDEFG... etc...how to count the amount of them.
View Replies
View Related
Mar 21, 2015
Write a GUI program to convert all lowercase letters in a string to uppercase letters, and vice versa.
For example, Alb34eRt will be converted to aLB34ErT.
View Replies
View Related
Mar 29, 2014
I'm trying to convert all letters in a 2D char array into number. As results, I want a = 0, b=1, c=2, ... z=25.
Then, I tried this as part of my code:
char [][] letters = {{'i', 'u'}, {'a', 'g'}, {'e', 'k'}};
for (int i = 0; i < letters.length; i++) {
for (int j = 0; j < letters[i].length; j++) {
if (letters[i][j] >= 'a' && letters[i][j] <= 'z') {
letters[i][j] = (char) ((letters[i][j] - 'a') + '0');
}
}
}
The result of my code is not what I expected before.
From 'a' to 'j', it worked well. But, from 'k' until 'z' it didn't print expected number.
What's wrong with my code and what is the correct way to fix it?
View Replies
View Related
Feb 6, 2014
I am getting run time Exception while converting String to Number....
public int convertToNumber(String numstr) {
int i = Integer.parseInt(numstr);
return i;
}
Here i am calling above Method convertToNumber().
if (validate.hasNumber(req.getParameter(LRSConstant.MOB_NUM))) {
bean.setMobno(ValidateUtils.getInstance().convertToNumber(
req.getParameter(LRSConstant.MOB_NUM)));
}
This is an Exception which i am getting at Run time
java.lang.NumberFormatException: For input string: "9700636702"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:461)
java.lang.Integer.parseInt(Integer.java:499)
[Code] ....
View Replies
View Related
Oct 21, 2014
any method or common algorithm to change a number taken from input to the word for that number? Such as input being "4", output would be "four", at least up to 59 as the larger program I'm trying to make involves time
View Replies
View Related
Dec 14, 2014
I was wondering if there was a way to check/view messages from my phone. I'm trying to create a program that will be able either read messages from my phone, or reply to them. I'm trying to get this to work for a Window Phone, but I don't know if there is a difference between doing it on a Windows Phone or Android. Most of the topics that somewhat relate to what I'm doing are all Android based.
I've looked at AT Commands, SMS Gateways, but I'm still not sure if it's entirely possible.
View Replies
View Related
Apr 20, 2014
I need a phonebook that allows the user to input up to 100 numbers but stop when they want to. I have the code for the array and input and output. I thought I had the do...while loop correct for asking the user if they want to input another name but its not working, even when you input "N" it still keeps going. Here's my code.
import java.util.Scanner;
import java.util.ArrayList;
public class PhoneEntry2 {
int x;
char repeat;
final int maxContacts = 100;
String[] pNums = new String[100];
[Code] ......
View Replies
View Related
Jun 22, 2014
I have a program for a phone directory. It needs to add, delete, append, and edit telephone records. I've gotten it to write and search the files. Just need to get it to delete and edit them.
Here's what I have so far:
import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import static java.nio.file.StandardOpenOption.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
[code]....
View Replies
View Related
Jul 9, 2014
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. 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();
[Code] ....
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.
View Replies
View Related
Jul 9, 2014
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.
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: ");
[code]....
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.
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.
View Replies
View Related
Jun 1, 2014
I have to read in a file that that has Student, Employee, Faculty....such as name, last name, salary...etc
Example of a file input
Java Code: Student, John, Doe, [email]johnDoe[At]yahoo.com[/email], 123,Wonderland Ave, 21323,TX
PhoneNumber,Cell,111,222,3333
Student, Jesus,Satan,[email]jesus[At]satan.com[/email,666, HeavenHell Dr., 666666,CA
PhoneNumber,Work,111,333,5555 mh_sh_highlight_all('java'); Java Code: while(input.hasNext()){
[code]...
There is more code, but it's repetitive. Now, I keep getting an error. Array of bounds. I believe i get the error because the phone number. The phone number is on the next line..I created a different arraylist for phonenumber, but I dont know how to match it with the correct person, student, employee...etc.
View Replies
View Related
Apr 4, 2014
The first 4 class below are the main classes while the last class is the testing class. I got it all to compile but for whatever reason there are several runtime errors. I have spent hours trying to figure out what they are, but I was only able to eliminate a few.
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Set;
import java.lang.*;
public class PhoneNetwork {
[Code] .....
View Replies
View Related
Oct 15, 2014
I can't figure out why my code doesn't work. My task is to replace for example ä=>ae, using this method String.charAt(int index). So here is my code:
public class pich {
public static void main(String[] args) {
String text = "Die süße Hündin Leica läuft in die Höhle des fülligen Bären "+
"Iliyan (ein Übergrößenträger), der sie zum Teekränzchen eingeladen hat."+
" An ihrem Öhrchen trägt sie modisch eine Ähre.";
String textOhneUmlaute = "";
[Code] ....
when I launch my code I get the same String and nothing has changed
View Replies
View Related
Apr 19, 2014
I am trying to reverse a string. Here is my code:
import java.util.*;
public class ReverseLettersInString {
public static void main (String[] args){
Scanner in = new Scanner (System.in);
String s;
[Code] .....
PROGRAM OUTPUT:
Enter string
me
e
The program returns e instead of em
View Replies
View Related
Jan 22, 2014
How to write a code that allows the computer to read a number from the keyboard, from 0-26 and print out that much of the alphabet
*For example
input = 3 output = ABC
input = 7 output = ABCDEFG
input = 0 output =
I tried this but it only gives me one letter that corresponds to the number
package pkg2911homework.pkg1;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner keys = new Scanner(System.in);
[Code] ....
View Replies
View Related