Write the following program: Read the name, customer number and telephone number
ID: 3694117 • Letter: W
Question
Write the following program:
Read the name, customer number and telephone number of customers. All these are strings. The length of the name is 25, of the customer number is 8, and telephone is 13. The format is
Name: <last name, first name> (Example : Davis, Paul)
Phone: dddddddddd (Example: 7878881234)
Customer No.: dddddd (Example: 123456)
After reading customer number, add the characters DS at the beginning. It must be converted to DSdddddd. (Example: DS123456)
The telephone number must be converted to (ddd)ddd-dddd. (Example: (787)888-1234)
The final result will be displayed as
Customer Name: ************, ************ (there is a space after comma)
Customer Number: ******** (a total of 8 characters)
Customer Phone Number: (***)***-**** (a total of 13 characters)
Every sub and function must have a heading. The main sub must have a heading that includes the name of the author, a description of the entire program and the date. In addition, each function’s heading must include the exact description of the task the function performs and the list of input and output data.
Remark. Use pencil, no pen. Write clearly and sequentially in one column. Your program must look exactly as if it was written on the computer. Use comment sign (‘) to state when you need to state what your next statement will perform.
Explanation / Answer
Program :-
---------------------
package com.app.chegg;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
public class CustomerDetails {
/**
* @author Mahindra
*
*/
/**
* This Method is used to convert to the Required phone format number
* @param phonefmt
*/
void phoneformat(long phonefmt){
//get a 12 digits String, filling with left '0' (on the prefix)
DecimalFormat phoneDecimalFmt = new DecimalFormat("0000000000");
String phoneRawString= phoneDecimalFmt.format(phonefmt);
java.text.MessageFormat phoneMsgFmt=new java.text.MessageFormat("({0}){1}-{2}");
//suposing a grouping of 3-3-4
String[] phoneNumArr={phoneRawString.substring(0, 3),
phoneRawString.substring(3,6),
phoneRawString.substring(6)};
System.out.println("Customer Phone Number :"+phoneMsgFmt.format(phoneNumArr));
}
/**
* This is Main Method for Reading the values from the keyboard
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter firstName :");
String lastName=br.readLine();
System.out.println("Enter LastName :");
String firstName=br.readLine();
System.out.println("Enter Phone Number :");
long phoneNo=Long.parseLong(br.readLine());
System.out.println("Enter Customer Number :");
int customerNo=Integer.parseInt(br.readLine());
System.out.println("Customer Name :"+firstName+" ,"+lastName);
String custNo="DS"+customerNo;
System.out.println("Customer Number :"+custNo);
CustomerDetails c=new CustomerDetails();
c.phoneformat(phoneNo);
}
}
output :-
------------------
Enter firstName :paul
Enter LastName :Davis
Enter Phone Number :7878881234
Enter Customer Number :123456
Customer Name :Davis ,paul
Customer Number :DS123456
Customer Phone Number :(787)888-1234
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.