Explanation of Solution
Program:
File name: “PhoneNumberFormat.java”
//Import necessary header files
import java.util.Scanner;
//Define a class named PhoneNumberFormat
public class PhoneNumberFormat
{
//Define main method
public static void main(String args[])
{
//Create an object for the Scanner class
Scanner scanner = new Scanner(System.in);
//do..while loop
do
{
//Prompt the user to enter a Phone Number
System.out.print("\nEnter the Phone Number: ");
String textPhone = scanner.nextLine();
/*Continue to accept the user input until the user enters 999*/
if (textPhone.contains("999"))
break;
//If the user enters a ten-digit phone number
if (textPhone.matches("[0-9]+") && textPhone.length() == 10)
{
//Print the result
System...
Trending nowThis is a popular solution!
Chapter 7 Solutions
Mindtap Computing, 1 Term (6 Months) Printed Access Card For Farrell’s Java Programming, 8th
- write an application that reads English-Language phrase and encodes it into morse code. also write an application that reads a phrase in morse code and converts it into the English-Language equivalent . Use one blank between each Morse-code letter and three blanks between each Morse-coded word.arrow_forwardIN JAVA When people enter their telephone numbers into a form they use many different formats. Some examples are: (444) 999-1234 4449991234 444.999.1234 In the PhoneNumbers class below, complete the cleanNumber method. It takes a string and extracts the numeric digits from the string. If there are exactly 10 numeric digits, the number is reformatted: (###) ###-#### and returned. If there are any other number of digits, the string "Error" is returned. Hint: Use the Character.isDigit method to check whether a character is a digit. public class PhoneNumbers{ /** Cleans a phone number. @param phoneNumber a phone number that should contain ten digits and possibly other characters @return the phone number in the form (###) ###-#### or the string "Error" if phoneNumber does not have ten digits */ public String cleanNumber(String phoneNumber) { // your work here ... for (int i = 0; i < ...; i++) { char ch = phoneNumber.charAt(i);…arrow_forwardIn this task you are being asked to write methods that manipulate string objects in java. Write a method that returns the count of the number of space characters that appear in the string object str. You may use the following header for this method: public static int countSpaceChatacter(String str) 1. Create a program called String methodsLab15.java and add this method in this class. 2. Use a scanner object for the string arguments input. 3. Call the method with appropriate string arguments. 4. Display appropriate message based on the return value.arrow_forward
- Create a program for Smalltown Regional Airport Flights that accepts either an integer flight number or string airport code from the options in Figure 8-33. Pass the user’s entry to one of two overloaded GetFlightInfo() methods, and then display a returned string with all the flight details. For example, if 201 was input, the output would be: Flight #201 AUS Austin Scheduled at: 0710 (note that there should be two spaces between 'Austin' and 'Scheduled'). The method version that accepts an integer looks up the airport code, name, and time of flight; the version that accepts a string description looks up the flight number, airport name, and time. The methods return a message if the flight is not found. For example, if 100 was input, the output should be Flight #100 was not found. If no flights were scheduled for the airport code entered, for example MCO, the message displayed should be Flight to MCO was not found.arrow_forwardWhen reading data from a text file, it is common to see numbers such as 12,345, $20, or 195*. Write a method that cleans a string containing digits by removing any characters that are not a digit or a - sign. Then convert to an integer and return the result. Numbers.java 1 public class Numbers 2 { /** Cleans a string containing an integer and converts it. @param number a string containing an integer and possibly extra characters @return the value of the number inside the string * / blic static int clean(String number) { 4 5 7 8 9 10 11 } 12 }arrow_forwardWrite a program that asks the user to enter 10 numbers, that range from 10-100. Make sure that you do not accept any numbers less than 10, if a user enters a number that is less than 10 then ask him again. Once the user enters all 10 numbers, sort the numbers entered in ascending order and print them out. CSharparrow_forward
- Write an application that allows a user to enter the names and birthdays of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value “ZZZ” for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names and display the corresponding birthdate or an error message if the name has not been previously entered. The loop continues until the user enters “ZZZ” for a name. Save the file as BirthdayReminder.java.arrow_forwardWrite a java application for Limpopo’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the user enters an invalid item. NB:ALSO SHOW OUTPUTarrow_forwardtion Consider the following code snippet. What should be placed in the blank to cause a message to be displayed when the user enters the same letter twice in a row? letter = input ("Enter the next letter in the alphabet: ") while letter != "": out of previous = letter ove flag letter = input ("Enter the next letter") if print ("Duplicate input") O a. letter == letter O b. alphabet[0] == previous %3D O c. letter == previous O d. alphabet[0] == letter %3Darrow_forward
- Write a java application for Limpopo’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the user enters an invalid item. ALSO SHOW OUTPUTarrow_forwardWrite an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names and display the corresponding birthdate or "Sorry, no entry for name" if the name has not been previously entered. The loop continues until the user enters ZZZ for a name.arrow_forwardWrite an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names and display the corresponding birthdate or "Sorry, no entry for name" if the name has not been previously entered. The loop continues until the user enters ZZZ for a name. import java.util.*; public class BirthdayReminder { public static void main(String[] args) { // Write your code here } }arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT