Question

In: Computer Science

A.Write a program that prompts for and reads the user’s first and last name (separately).Then print...

A.Write a program that prompts for and reads the user’s first and last name (separately).Then print the initials with the capital letters. (Note that we do not expect that inputs from users are case-sensitive. For example, if the user’s input of the first name is robert and of the last name is SMITH, you should print R.S.)

B.Write a program that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashed in the output. Do not let the first three digit 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 655. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be determined separately.

-use java

Solutions

Expert Solution

Answer 1:

import java.util.Scanner;

public class Example1 {
public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   //reading first name and last name
   System.out.println("Enter first name");
   String f=sc.next();
   System.out.println("Enter last name");
   String l=sc.next();
   //appending first char from each string and converting into uppercase
   String in = f.toUpperCase().charAt(0)+"."+l.toUpperCase().charAt(0);
   System.out.println(in);
}
}

Answer 2:

import java.util.Random;

public class RandomPhone {
   public static void main(String[] args) {
       String phone = "";
       Random r = new Random();
       String firstThree = "";
       // generating first three numbers until it has other 8 and 9
       while (true) {
           firstThree = "" + (r.nextInt(899) + 100);
           if (!firstThree.contains("8") && !firstThree.contains("9"))
               break;
       }
       phone = firstThree;
       // generating the next 3 numbers less than 655
       phone = phone + "-" + (r.nextInt(555) + 100);
       // generating last 4 digits
       phone = phone +"-"+ (r.nextInt(9999) + 1000);
       System.out.println(phone);
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

The program reads a text file with student records (first name, last name and grade on...
The program reads a text file with student records (first name, last name and grade on each line) and determines their type (excellent or ok). <--- Completed Need help on this Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "all" - prints all student records (first name, last name, grade, type). "excellent" - prints students with grade > 89. "ok" - prints students with grade <= 89. "end" -...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
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...
Write a program that prompts the user to input their first name from the keyboard and...
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE ! You...
jgrasp environment, java write a complete program that prompts the user to enter their first name,...
jgrasp environment, java write a complete program that prompts the user to enter their first name, middle name, and last name (separately). print out thier name and initials, exactly as shown: your name is: John Paul Chavez your initials are: J. P. C. use string method chartAt() to extract the first (zero-th) character from a name(the name is a string type): username.charAt(0). thank you.
Write a program that prompts for and reads in the two side lengths of a right...
Write a program that prompts for and reads in the two side lengths of a right triangle (floating point numbers) and then calls a float-valued function, hypot1, that calculates and returns the length of the hypotenuse of the triangle. The program then displays the two side lengths and the hypotenuse length. Note: The hypot1 function returns the hypotenuse length – it does not display it; the function should not contain any cout nor cin statements. Math review: Recall that for...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to...
PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to be processed. If ?≤0 your program must display an error message and terminate; otherwise it does the following for ? times: Write a program that prompts for and reads the number ?n of spheres to be processed. If ?≤0n≤0 your program must display an error message and terminate; otherwise it does the following for ?n times: Prompts for and reads the volume of a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT