2.29 Random Phone Number (Java)
Write a program that creates and prints a random phone number of the form 668-555-xxxx where xxxx is a 4-digit randomly generated number. Include the dashes in the output. Think through how you can guarantee a 4-digit number.
Your output should look like:
A random phone number: 678-555-1234
Given:
import random number
public class PhoneNumbers
{
//-----------------------------------------------------------------
// Produces a random phone number of the form 678-555-xxxx.
//-----------------------------------------------------------------
}
}
Answer:
Java code:
import java.util.*;
class A {
public static void main(String args[])
{
Scanner s=new
Scanner(System.in);
Random r=new Random();
int a=r.nextInt(10000);
System.out.println("668-555-"+a);
}
}
Execution screenshots:

Note: please like the answer if you are satisfied with it. Thank you in advance.
2.29 Random Phone Number (Java) Write a program that creates and prints a random phone number...
***** TO BE WRITTEN IN JAVA *****
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. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be...
This is Python
The program should accept input from the user as either 7-digit
phone number or 10-digit. If the user enters 7 characters, the
program should automatically add "512" to the beginning of the
phone number as the default area code. Dash (hyphen) characters do
not count in input character count, but must not be random. If the
user enters dashes the total character count must not exceed
12.
The program should not crash if the user enters invalid...
In Java, write a program called SCATTEREDLNS that prints out lines that contain a random number of “x” characters (between 5 and 20 inclusive) until it prints a line that contains 16 or more characters. For example, it might look something like this xxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxx xxxxxxxxxxx xxxxxxxxxxxxxxxxx
Write a program that produces the following output for a random number of digits on a row and a random number of rows. 1****** 12***** 123**** 1234*** 12345** 123456* 1234567 Write a program that calculates the following series: i=1n(12)n=12+14+18+...+12n (hint: we need to talk about integer division) Use for loops to write a code segment that prints the following output. 1 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16 5 10 15 20
Write a program in C that creates an array of 100 random numbers from 0-99. The program sums the random numbers and prints the sum. It then writes the numbers to a new file using open, close and write. Then looks in the current directory for files that match the pattern “numbers.XXXX”. For each file, open the file and read the file. You can assume that the file will contain 100 integers. Sum the integers. Print the filename and the sum...
This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...
Write a script that works in vim: We are given a Java program RandomTest.java that generates specified number of random integers in the range [0...99]. The program prints FAIL if either 0 or 99 is generated (along with a count of how many times). Otherwise it prints PASS. The program takes the number of random integers to generate as a command line argument as shown below. Note that the given results each time is is run. [an@localhost ~] java Random...
Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...
Q1. Write program calculate the final price of a purchased item using values entered by the user Hint: you are required to use formatting output for number, currency and percentage. --------------------[Print Receipt] ------------ Enter the quantity: 6 Enter the unit price: $1.98 Subtotals: $10.14 Tax: $ 0.61 at 6% Total: $10.75 ------------------------------------------------ Q2. Write a program that prompts for and reads the users’ first name and last name, Job title, DOB (date of Birth), and the Email address (separately). Then...
IN JAVA Create a class called Telephone that accepts a phone number in the constructor. For the purposes of this assignment, phone numbers may be any length. Make a method called getPossibilities that returns all possible phonewords for that phone number. A phoneword is what you get when a phone number is converted in to letters. For example, the phone number 922-6966 could be re-written as ZAA-MZNO. Look at your phone to see where those letters came from. DO NOT...