Question

In: Computer Science

When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name.

When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name.

using name John Smith

phone number 1234567893

Using net beans take the first two letters from smith and first 3 numbers from the phone number and combine them to one line like this sm123.

Solutions

Expert Solution

#source code:

import java.util.*;

import java.lang.*;

public class Q{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

String fname,lname,phonenumber;

System.out.print("Enter your first and last name:");

fname=sc.next();

lname=sc.next();

System.out.print("Enter your phone number:");

phonenumber=sc.next();

char[] varchar = phonenumber.toCharArray();

int count=0;

for(char c: varchar){

if(Character.isDigit(c)){

count=count+1;

}

}

if(count==10 &&phonenumber.length()==10){

String data;

char[] lnamec=lname.toCharArray();

data=Character.toString(lnamec[0])+Character.toString(lnamec[1]);

data=data.toLowerCase();

data+=Character.toString(varchar[0])+Character.toString(varchar[1])+Character.toString(varchar[2]);

System.out.println(data);

}else{

System.out.println("Nov valid phone number");

}

}

}

#output:

 


Related Solutions

Write a java program to accept a telephone number with any number of letters. The output should display a hyphen after first 3 digits and subsequently a hyphen (-) after very four digits.
Write a java program to accept a telephone number with any number of letters. The output should display a hyphen after first 3 digits and subsequently a hyphen (-) after very four digits. Also, modify the program to process as many telephone numbers as the user wantscode optimization: no unnecessary variables , if statements and counterssample output screen shown with 3 cases(atleast one with blank spaces ect.)Descriptive block and inline comments include.
Write the pseudocode that prompts the user for their first and last name. Display the first...
Write the pseudocode that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user. Ask the user to input a phone number. The program checks which part of Colorado a phone number is from using the values below. If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none...
When analyzing the last digits of telephone numbers in Sandtown, it was found that among 1500...
When analyzing the last digits of telephone numbers in Sandtown, it was found that among 1500 randomly selected phone numbers, 225 had zero as the last digit. If the digits are selected randomly, the proportion of zeroes should be 0.1 because from probability, 0 is one of the 10 possible digits. Use the p-value method with a 0.01 level of significance to test the claim that the proportion of zeroes is not equal to 0.1. Use the sample data to...
When analyzing the last digits of telephone numbers in Sandtown, it was found that among 1500...
When analyzing the last digits of telephone numbers in Sandtown, it was found that among 1500 randomly selected phone numbers, 225 had zero as the last digit. If the digits are selected randomly, the proportion of zeroes should be 0.1 because from probability, 0 is one of the 10 possible digits. 1. Use the p-value method with a 0.01 level of significance to test the claim that the proportion of zeroes is not equal to 0.1. 2. Use the sample...
When analyzing the last digits of telephone numbers in Sandtown, it was found that among 1500...
When analyzing the last digits of telephone numbers in Sandtown, it was found that among 1500 randomly selected phone numbers, 225 had zero as the last digit. If the digits are selected randomly, the proportion of zeroes should be 0.1 because from probability, 0 is one of the 10 possible digits. Use the p-value method with a 0.01 level of significance to test the claim that the proportion of zeroes is not equal to 0.1. Be sure to use the...
How to display in SQL Server, for example, all the author First Names are FIVE LETTERS...
How to display in SQL Server, for example, all the author First Names are FIVE LETTERS LONG if I have the Author Table. I used the WHERE LENGTH ua_fname=5   This is not returning names with 5 letters. Can someone please suggest to me the correct one?
Assume that the last two digits on a car number plate are equally likely to be...
Assume that the last two digits on a car number plate are equally likely to be any of the 100 outcomes{00, 01, 02, ........ 98, 99}. Peter bets Paul, at even money, that at least 2 of the next n cars seen will have the same last two digits. Does n=16 favour Peter or Paul? What value of n would make this a pretty fair bet?
In a two digit number the sum of the digits is 9. Also, when 27 is subtracted from the number the digits are reversed. Find the number?
In a two digit number the sum of the digits is 9. Also, when 27 is subtracted from the number the digits are reversed. Find the number?
5. Write a C++ statement or statements that will:       Print the first two digits and the  last...
5. Write a C++ statement or statements that will:       Print the first two digits and the  last two digits of any 4 digit number stored in an integer variable n.         For example, given int n = 5623, print 56    23. 6. Write  C++ statements that will align the following three lines as printed in two 20 character columns. Name                                                 Years President Abraham Lincoln                                 1860-1865 Thomas Jefferson                               1801-1809 7.  Write a C++ statement or statements that will Output if a string has a length greater than 10, equal...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT