Developing A Program That Inputs Telephone Numbers
Jan 26, 2014
Develop an algorithm for a Java program that takes as input a single letter and displays the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way:
The screen dialog might look like this: Enter a single letter, and I will tell you what the corresponding digit is on the telephone. R The digit 7 corresponds to the letter R on the telephone.
The program should display a message indicating that there is no matching digit for any non-alphabetic character entered by the user. Also, the application should recognize only uppercase letters. If a user enters a lowercase letter, the program should display an error message. Prompt the user with an informative message for the input value as shown above.
The application should include the input letter as part of the output.
Write the algorithm to solve this problem including steps for prompting the user, getting input from the keyboard, and displaying the results.
Write the Java program that you designed, using your algorithm as a guide. Use your algorithm as comments in the body of the main method.
Use proper indentation, and meaningful identifiers throughout the code.
I'm trying to put together a method that formats telelphone numbers, but there's a part of my code that not working. If I enter (305)912-5458 into the variable phoneNumb I get an index is out of range error. I added a lot of system out messages so that I can try to get an idea of why the code was crashing.
public static void main(String[] args) { int intBegin = 0; int intEnd = 1; int length; String charact; StringBuilder numbuilder = new StringBuilder();
[Code] .....
The error message I'm getting is:
run: The length is 13 intBegin is at 0 intEnd is at 1 index is at 0 Charcter ( was not inserted
Write a program to calculate the telephone charges for four customers. The data for each customer consists of NAME, PREVIOUS METER READING, PRESENT METER READING. The difference between the two readings gives the number of units used by the customer for the period under consideration.
The amount due for each customer is calculated by: UNITS USED * RATE PER UNIT + RENTAL CHARGE The rate per unit and rental charge is assumed to be the same for all customers and must be input once only.
Your program must:
a. Input the rate and rental charge b. Read the data for each customer and calculate the amount due c. Print the information under suitable headings d. Calculate and print the total amount due to the telephone company
import java.util.Scanner; public class Bill { public static void main(String[] args) { Scanner console = new Scanner(System.in); //final variables Premium Service final double monthlyChargeP = 25.00; final double FordayminutesP = 0.10;
[Code] ....
I can't find the syntax on {} my block is highlighted red in my application
import java.util.Scanner; public class CountStringNumbers { // show the number of Strings that were numbers . . .. public static void main(String []args){ int count = 0; int countNumbers=0; Scanner input=new Scanner(System.in);
[code]...
can count the numbers from 0-9 if the user puted but if it is 10 it doesnt count it , and i need to write all the numbers to have that option. . . . Is there an easy way that includes all the numbers? like if(word.equals(number)){<<<???? (numbers) i know htat doesnt work but is there anything similar ?? ??
countNumbers++; } System.out.println("Type Something , , , and to end the the termination type STOP"); word=input.nextLine(); count++; } System.out.println("You wrote "+count+" lines wich from those lines "+countNumbers+" were numbers and the programe terminated "); } }
I have to get the user to enter in 10 numbers and with those 10 numbers I have to find the total, average, smallest, largest numbers in the set the user inputs. I have the total and average already figured out but how would you go about trying to find the largest and smallest numbers within this set of code.
import java.util.*; public class testhw7 { public static void main (String [] args) { Scannernumberin = new Scanner (System.in); doublevalue[]; doubletotal;
I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:
insert "}" to complete StatementKALENDER_3.java insert "}" to complete BlockKALENDER_3.java
The code:
import java.util.*; import java.util.Scanner; public class KALENDER_3 } public static void main(String[] args){ Scanner scanner = new Scanner (System.in); System.out.print("Skriv ett manadsnummer: ");
[code].....
I think I have just forgot to put in a few { } symbols, maybe an open loop?
I am trying to write a program for converting positive binary inputs into hex.Why am i getting this errors while compiling my binary to hex converter..
Exception in thread "main" java.lang.NumberFormatException: For input string: "148.0" at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65) at java.lang.Long.parseLong(Long.java:441) at BinToHex.convertbintohex(BinToHex.java:24) at Test.main(Test.java:4)
Here is my BinToHex class
import java.io.*; public class BinToHex { double tempDec,fractionpart; long longofintpart,templongDec; String inpu ="1001.01"; String hexOutput,intpart,tempDecString,hex = null;
Following is the code for my assignment where a user inputs his full name in a string from keyboard. It should be done using BufferedReader. The program will give his initials as output.
############################
For example: User inputs-> Ram Kumar Das
Program Returns-> R.K.D.
I am written the following piece of code. It does not return the correct output. If "Ram Kumar Das" is given as input, it gives R.K.K. as output. Arrays and objects are strictly not allowed.
Java Code:
import java.io.*; public class Assignment { static int i=0; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main (String args[]) throws IOException
I am new to java, i can develop basic java programs but am not really good at it. How should i pursue and how should i start. I know the game rules.Do i need to learn swings for the same?
i can develop basic java programs but am not really good at it.I have been given this assignment of developing UNO game in java and have been given 10 days. How should i pursue and how should i start.I know the game rules.Do i need to learn swings for the same?
am trying to Develop a download manager that will improve the downloading process, by splitting big files into different parts, and download each part of the file parallel and then combine them properly Just like JDownloader not really too complex like it though but more like it especially the split download part of it. I was able to get a script from some eBook but that doesn't really solve my problem as it only downloads pause and resumes which is not really what am looking for.
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
I post the code I'm developing for a tetris-based characters. The problem I have is that I can't print the piece within the board. I haven't any error.
Class Piezas
Java Code:
public class Piezas {
public Piezas() {} //atributos private int i; private int j; private char m[][]; private int formaPieza;
I'm having problems with the public static void main(String args[]) part. Everything else is correct before this, my teacher has checked that. I have been trying to research why it won't compile right and can't find any errors.
/* Chapter 6:Telephone Purpose:This project displays a telephone keypad you can use to type in a phone number. */ import java.awt.*; import java.datatransfer.*; import java.awt.event.*; import javax.swing.JOptionPane; public class Telephone extends Frame implements ActionListener
Write an interface Directory to manipulate entries in a telephone directory for the University. The interface must support the following operations:
1) The ability to insert new entries into the directory. Entries should be stored in alphabetical order of surname. 2) Delete entries from the directory either by name or number 3) Provide a lookup method that will find the extension no of a member of staff given his/her name. You should try to make this method run as efficiently as possible. 4) Change a person's telephone number 5) Print the telephone directory in a neatly tabulated fashion.
Write a class ArrayDirectory that implements this interface using an array to store the telephone directory information. The class must store the surname and initial for each member of staff and their telephone extension (a four digit number which may start with a zero). You may find it useful to define a class Entry to store information about individual entries. The entries should be read into the array from a text file consisting of multiple lines in the following format:
Surname<tab>Initials<tab>Telephone extension
Write a main program that reads in data from a file and then tests all the methods of your class interface. Note it is not necessary to write data back to disk (even if it has changed) in this project.
For data insertion and lookup, you should measure the performance for the average case (e.g. looking up a record in the middle of the data). To do this you can use the static method System.currentTimeMillis() which returns the time in milliseconds. To get an accurate measure of the time to perform an operation it is a good idea to perform each operation 1000 (or even 10000) times and measure the time taken. This will remove any problems due to the system clock having a coarse granularity (not ticking very often). Make sure you only time the method and not any input/output associated with it. Your documentation should include a discussion of these results.
Part 2
You decide that your solution to part 1 may be too slow to be useful when used with a real large telephone directory and make the following changes to attempt to improve the performance of your program:
1). Provide a second implementation (ListDirectory) of the Directory interface using the Java Collections List interface and LinkedList classes. 2). The changes in 1) should make adding, deleting and modifying records more efficientbut will probably reduce the time to lookup numbers. To overcome this you use a technique called hashing. Instead of storing all the records on one list you use a series of lists. The data for all people whose surname begins with "A" is stored on the first list, records for all people whose surname begins with "B" on a second list and so on. Write a third implementation (HashDirectory) of the Directory interface using this technique.
Again, you should measure the performance for the best, worst and average cases of implementations 1) and 2) above. Compare the efficiency of each of the 3 implementations in your documentation.
Part 3
Choose one of your 3 implementations from Parts 1 and 2 and embed it in a graphical user interface that allows users to perform all the methods in the Directory interface using a mouse and keyboard appropriately.
I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.
import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Scanner; public class TelephoneGenerator { String phoneNumber; char numberLetters[][] = {
[Code] ....
I am getting an error dealing with the main class.
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!
I have to write a program that find the sum of two numbers 62 and 99 and stores them in a variable named total. However, I have one error that I just can't get rid of and can't tell what it is. I'm using jGrasp and here's what it says:
Programming Challenge #5.java:14: error: class SumofTwoNumbs is public, should be declared in a file named SumofTwoNumbs.java public class SumofTwoNumbs { ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
and here: is my code:
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** // This program has variable of several of the integer types. public class SumofTwoNumbs { public static void main(String[] args) {
i'm trying to write a program that uses an array to store 10 numbers. The numbers should be randomly generated ( Math.random() ), and they should be between 1 and 100 ( 1 and 100 inclusive ). The program should produce an output like the one below:
Element 1 = 23 ( Odd ) Element 2 = 15 ( Odd ) Element 3 = 32 ( Even ) Element 4 - 10 ( Even ) Element 5 - 99 ( Odd ) Element 6 - 1 ( Odd )
[Code]...
I have written code for this but its only showing me 0's after first number can you check whats wrong with my code. my code is.
class even/odd{ public static void main(String[]args){ int y=0; int z=0; int[] array= new int[11]; for(int x=1; x <array.length ; x++){ array[x]= (int) (Math.random()* 100);
This program is supposed to ask for the operator (+ or -) then ask you for two numbers and do the math. When I run it it comes up- Enter operator. When I say add or sub nothing happens. Here it is:
import java.util.Scanner; public class Echo1{ public static void main(String args[]){ Scanner userInput = new Scanner(System.in); System.out.println("Enter Operator"); String operator = userInput.next();
im trying to do a program to find if numbers are consecutive or not! if they are consecutive i need a true as a return and a false when they are not... i did this program and im sure i did something wrong because i keep only true returns ..
Example: (3,5,7) (1,2,2) (7,7,9) should return a false! Java Code: import java.util.*; public class Consecutive{ public static void main (String [] args){ Scanner console= new Scanner(System.in); System.out.println("Enter three numbers"); String numbers = console.nextLine(); System.out.println( "The numbers (" + numbers + ") is '" + consecutive( numbers ) + "'" ); }//end of main
I am trying to write a program that takes two numbers and multiplies them. I got this idea from this running conversion program
import java.util.Scanner; public class Convert { public static void main (String [] args) { Scanner reader = new Scanner (System.in); double farenheit; double celsius;
[code]...
i am getting a cant find symbol for the output = (alpha*beta) line..Also, am I using the reader object correctly ? hould I create two reader objects as there are 2 inputs needed?
I have to write a program that displays the first 100 pentagonal numbers using different methods. This is what I have so far:
Java Code:
public class FivePointOne{ public static void main(String[]args){ System.out.println("The the pentagonal numbers are: "); } //this method will find the penagonal numbers public static int getPentagonalNumber(int n){
[Code] ....
But when I compile it to test it out I receive the error message "Illegal start of expression," ';' expected, and "reach end of file while parsing".